I want to convert from an array to a List
public static void main(String[] args) {
String arr[] = {"orange","apple","cherry","melon","grape"};
List<String> list = Arrays.asList(arr);
Assign Arrays.asList with arr as an argument to list
List<String> list = Arrays.asList(arr);
list.add("banana");
(Cause) Arrays.asList () does not accept List method operations such as add and delete
List<String> list = Arrays.asList(arr);
List<String> list2 = new ArrayList<>(list);
list2.add("banana");
Assign list to list2 as an argument of ArrayList If you write the above briefly
List<String> list = new ArrayList<>(Arrays.asList(arr));
list.add("banana");
Recommended Posts