Also print
vowelsList.size();
for both, and you'll see the difference ;)
Spoiler:
The generic type of the first method is char[]
, so you'll get a list of size one. It's type is List<char[]>
. The generic type of your second code is Character
, so your list will have as many entries as the array. The type is List<Character>
.
To avoid this kind of mistake, don't use raw types! Following code will not compile:
List<Character> vowelsList = Arrays.asList(new char[]{'a','e','i','o','u'});
Following three lines are fine:
List<char[]> list1 = Arrays.asList(new char[]{'a','e','i','o','u'}); // size 1
List<Character> list2 = Arrays.asList(new Character[]{'a','e','i','o','u'}); // size 5
List<Character> list3 = Arrays.asList('a','e','i','o','u'); // size 5