I am freaked out about the following code and surprised that it didn't work. Here I want to compare two ArrayLists the way I want as in below. So I can't get match for "Green" just because it is added to the ww list with a space contained " Green" even I used trim() but still doesn't work. Thanks you very much for your expertise to help me with this strange error.
ArrayList<String> ww = new ArrayList();
ArrayList<String> mm = new ArrayList();
ww.add("Orange");
ww.add(" Green".trim());
mm.add("Orange");
mm.add("Green");
for ( String x:ww){
for ( y:mm){
if (x==y){
System.out.println(x);
}
}
}
After running:
Orange