I have two arraylist that has some elements I am comparing the elements of both arraylists and trying to extract the elements in third arraylist that are not common in both lists.
This is what I have done so far:
public class Details
{
public static void main(String [] args)
{
ArrayList<String> al1= new ArrayList<String>();
al1.add("hi");
al1.add("How are you");
al1.add("Good Morning");
al1.add("bye");
al1.add("Good night");
ArrayList<String> al2= new ArrayList<String>();
al2.add("Howdy");
al2.add("Good Evening");
al2.add("bye");
al2.add("Good night");
//Storing the comparison output in ArrayList<String>
ArrayList<String> al3= new ArrayList<String>();
for (String temp : al1)
al3.add(al2.contains(temp) ? "Yes" : "No");
System.out.println(al3);
}
}
OUTPUT
[No, No, No, Yes, Yes]
I don't want output in yes or no form I want elements in new array list that are no common in both lists.
Someone please let me know how can I achieve desired result. Any help would be appreciated.
THANKS