The title sheds good light on the trouble I am having, here is my code:
// fields required for traversal
private Queue<ArrayList<String>> q;
private ArrayList<ArrayList<String>> r;
Set<String> stringList = getMeStrings();
for(String s : stringList)
{
ArrayList<String> stringsRoute = new ArrayList<String>();
stringsRoute.add(getSomeString());
stringsRoute.add(s);
if(!r.contains(stringList))
{
if(!q.contains(stringList))
{
q.add(stringList);
}
r.add(stringList);
}
}
My If statement inside the For loop always fails, and I think the reason is because I am creating a new ArrayList object (different reference) and my If statement isn't checking to see if the contents of each of the ArrayLists in [ r ] contain the same elements in same order .. etc
I know one needs to use .equals in order to find out if two ArrayLists are similiar, but I have an ArrayList that houses many other ArrayLists.
How can I check if the parent ArrayList contains an ArrayList that equates to the new ArrayList I am creating?
I hope it is clear what I am trying to achieve.
Thanks
StringsRoute
looks like a class instead of a variable! – Veger Jan 23 '13 at 14:13stringsRoute
will always contain 2 elements? – jlordo Jan 23 '13 at 14:15StringTuple
and provide anequals
method for that and use aList<StringTuple>
instead ofList<List<String>>
. – jlordo Jan 23 '13 at 14:20