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);
7 Answers
+ 1
my declaration
ArrayList al=new ArrayList();
0
what error ?.
you can also use foreach method in java8
al.forEach(c -> System.out.println(c));
0
what's the error ?
0
ArrayToList.java:25: incompatible types
found : java.lang.Object
required: char
for(char c:al)
^
0
can i see how your arraylist declaration ?
0
you'll need to put the type of its value.
ArrayList<Character>al=new ArrayList<>();
0
Taste yes thanks :)