0

Using for each in Arraylist

Hi all I define a arraylist called to "al". And fill it by characters. I want print it by for each But got error Can i do? for(char c:al) System.out.println(c);

1st Jul 2019, 3:34 PM
Hadi
Hadi - avatar
7 Answers
+ 1
my declaration ArrayList al=new ArrayList();
1st Jul 2019, 4:41 PM
Hadi
Hadi - avatar
0
what error ?. you can also use foreach method in java8 al.forEach(c -> System.out.println(c));
1st Jul 2019, 4:08 PM
Taste
Taste - avatar
0
what's the error ?
1st Jul 2019, 4:30 PM
Taste
Taste - avatar
0
ArrayToList.java:25: incompatible types found : java.lang.Object required: char for(char c:al) ^
1st Jul 2019, 4:35 PM
Hadi
Hadi - avatar
0
can i see how your arraylist declaration ?
1st Jul 2019, 4:40 PM
Taste
Taste - avatar
0
you'll need to put the type of its value. ArrayList<Character>al=new ArrayList<>();
1st Jul 2019, 4:43 PM
Taste
Taste - avatar
0
Taste yes thanks :)
1st Jul 2019, 4:45 PM
Hadi
Hadi - avatar