|
to compare two arraylist
u can use following code to check two arraylists
import java.util.*;
public class Ex {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList al1=new ArrayList();
al1.add("a1");
al1.add("a2");
al1.add("a3");
ArrayList al2=new ArrayList();
al2.add("b1");
al2.add("a2");
al2.add("a3");
if(al1.size()==al2.size()){
Object[] o1=al1.toArray();
Object[] o2=al2.toArray();
if(Arrays.equals(o1,o2)){
System.out.println("Both arraylists are equal");
}else{
System.out.println("Both arraylists are not equal");
}
}
else{
System.out.println("Both arraylists are not equal");
}
}
}
|