I have two arraylist
ArrayList<String> a1
ArrayList<String> a2
I want to check if all the elements of a1 are present in a2.
this is what I was trying which I got from a question on SO
if (Arrays.asList(a2).containsAll(Arrays.asList(a1)))
{a2ContainsA1=true;}
which is not giving consistent results…is there any other way of doing this?
Not sure if I understand your question correctly, why are you using
Arrays.asList()?Tried this:
And it outputs
trueAdding an additional element to
a1will fail it (as expected):And it outputs
false