+ 1

Problem converting Array to ArrayList

Same error with E, T example https://code.sololearn.com/cmNQH014sVF0/?ref=app

25th Nov 2021, 9:15 PM
Billy Beagle
3 ответов
+ 3
You could use these for arrays char[] arr = {'2', '5'}; ArrayList<Character> list = new ArrayList<Character>(); for (char ch: arr) list.add(ch); or Character[] arr = {'2', '5'}; ArrayList<Character> list = new ArrayList<>(Arrays.asList(arr)); or Character[] arr = {'2', '5'}; ArrayList<Character> list = new ArrayList<>(); list.addAll(Arrays.asList(arr)); This is the result. for (char i : list) System.out.println(i); or for (Character i : list) System.out.println(i); // Keep learning & happy coding :D
26th Nov 2021, 12:23 AM
SoloProg
SoloProg - avatar
+ 2
I think asList doesn't work for char arrays. Maybe try ArrayList<Character> li = new ArrayList<Character>(); for (char ch: arr) { li.add(ch); }
25th Nov 2021, 9:34 PM
Lisa
Lisa - avatar
0
Thank you both, now it works!
26th Nov 2021, 6:07 AM
Billy Beagle