Reputation: 5144
when I write this, it has the error "cannot instantiate the type List < Character>"
Character[] ray = {'a','s','e'};
List<Character> l = new List<Character>(Arrays.asList(ray));
But when I write this, there is no error
Character[] ray = {'a','s','e'};
List<Character> l = Arrays.asList(ray);
So why is that?
edit: and what is the type of l in the second example?
Upvotes: 1
Views: 255
Reputation: 54312
The problem is that List
is an interface (it defines some methods, but doesn't implement them). Try using a class that implements it, like ArrayList
or LinkedList
:
List<Character> l = new ArrayList<Character>(Arrays.asList(ray));
Upvotes: 6