Operating sublists efficiently
Yes, this doesn't look pretty. Consider converting the list to sets or using RegEx.

ArrayList&lt;String&gt; A = new ArrayList&lt;String&gt;();
A.add("Z");
A.add("Z");
A.add("C");
A.add("X");
A.add("Z");

Set&lt;String&gt; set = new HashSet&lt;String&gt;(A);

for(String temp:set)
    System.out.println(temp);           


Sublists: 

List&lt;String&gt; subList = alist.subList(2, 4);


Use retainAll to get intersections:

listOne.retainAll(listTwo) ;  
boolean areEqualNotSamePosition = listeOne.size();