ArrayList in Java [on hold]
- by JNL
I was implementing a program to remove the duplicates from the 2 character array.
I implemented these 2 solutions, Solution 1 worked fine, but Solution 2 given me UnSupportedoperationException. I am wonderring why i sthat so?
The two solutions are given below;
public void getDiffernce(Character[] inp1, Character[] inp2){
// Solution 1:
// **********************************************************************************
List<Character> list1 = new ArrayList<Character>(Arrays.asList(inp1));
List<Character> list2 = new ArrayList<Character>(Arrays.asList(inp2));
list1.removeAll(list2);
System.out.println(list1);
System.out.println("*********************************************************************************");
// Solution 2:
Character a[] = {'f', 'x', 'l', 'b', 'y'};
Character b[] = {'x', 'b','d'};
List<Character> al1 = new ArrayList<Character>();
List<Character> al2 = new ArrayList<Character>();
al1 = (Arrays.asList(a)); System.out.println(al1);
al2 = (Arrays.asList(b)); System.out.println(al2);
al1.removeAll(al2); // retainAll(al2);
System.out.println(al1);
}