mardi 31 mars 2015

java list addAll function [duplicate]


This question already has an answer here:




New to java. I created two List objects and tried to add the second list to the first one, code as below.



import java.util.*;

public class t {
public static void main(String[] args){

String[] things = {"a", "b", "c", "d", "e", "f"};
List<String> list1 = Arrays.asList(things);

String[] things2 = {"g", "h", "i", "j"};
List<String> list2 = Arrays.asList(things2);

list1.addAll(list2);
}
}


it can successfully compile, but when I run it, error information as below:enter image description here


I am wondering what has happened here. Why I cannot use addAll function. Since two lists are both declared to hold String types.


Aucun commentaire:

Enregistrer un commentaire