I have 2 arraylists of string object.
List sourceList = new ArrayList();
List destinationList = new ArrayList
If your requirement is to maintain the insertion order plus check the contents of the two arraylist then you should do following:
List listOne = new ArrayList();
List listTwo = new ArrayList();
listOne.add("stack");
listOne.add("overflow");
listTwo.add("stack");
listTwo.add("overflow");
boolean result = Arrays.equals(listOne.toArray(),listTwo.toArray());
This will return true.
However, if you change the ordering for example:
listOne.add("stack");
listOne.add("overflow");
listTwo.add("overflow");
listTwo.add("stack");
boolean result = Arrays.equals(listOne.toArray(),listTwo.toArray());
will return false as ordering is different.