I have used the below code:
The output should be each word within the string in the ArrayList occurring only once.
O/P:
"This is a list and Arraylist with set". Any suggestion will be appreciated.
public class ArrayListTest {
public static void main(String[] args) {
String s1="This is a list";
String s2="This is a list and Arraylist";
String s3="and Arraylist with set";
ArrayList<String> al = new ArrayList<String>();
al.add(s1);
al.add(s2);
al.add(s3);
System.out.println(al);
LinkedHashSet<String> lhs = new LinkedHashSet<String>();
lhs.addAll(al);
System.out.println(lhs);
}
}