프로그래밍언어

Arrays.asList() - 사용 시 주의

springship 2019. 7. 29. 15:01

// List A 에 포함된 요소 B 에서 제거
String[] name1 = {"ABC", "CBB", "KKK"};
String[] name2 = {"ABC", "CBB"};

List listA = Arrays.asList(name1);
List listB = new ArrayList<>(Arrays.asList(name2));

//listA.remove("ABC");  // 이 경우 에러 발생 - java.lang.UnsupportedOperationException
listB.remove("ABC");

// for (String s : listB) {
// listA.remove(s);
// }
System.out.println(">" + listA);
System.out.println(">" + listB);

 

--------------------------------------------------

 

>[ABC, CBB, KKK]
>[CBB]