//How to compare Two array both are equal or not?
import java.util.Arrays;
public class ArrayCompare {
public static void main(String[] args) {
int [] x= {10,20,30,40,50};
int [] y= {10,20,30,40,50};
if(Arrays.equals(x, y))
{
System.out.println("x and y array are same");
}
else
{
System.out.println("x and y array are not same ");
}
String [] s1= {"govind","ballabh","khan"};
String [] s2= {"govind","ballabh","khan"};
if(Arrays.equals(x, y))
{
System.out.println("s1 and s2 array are same");
}
else
{
System.out.println("s1 and s2 array are not same ");
}
if(Arrays.deepEquals(s1,s2))
{
System.out.println("s1 and s2 array are same");
}
else
{
System.out.println("s1 and s2 array are not same ");
}
}
}
o/p:--------------------------------
x and y array are same
s1 and s2 array are same
s1 and s2 array are same
No comments:
Post a Comment