我正在实施一个程序以从 2 个字符数组中删除重复项。我实现了这两个解决方案,解决方案 1 运行良好,但解决方案 2 给了我 UnSupportedOperationException。为什么呢?错误在行al1.removeAll(al2);
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); // error is here
System.out.println(al1);
}