creating an arraylist of char? how to do this

I tried to do this:ArrayList<char> list = new ArrayList<char>();but it won't work, instead it gives me an error of:syntax error on token char; dimensions expected after this token
[220 byte] By [aditya15417a] at [2007-11-26 17:55:19]
# 1

You can only add Objects to Collections, not primitive types.

So you need to use the wrapper class for the char type, which is the Character class.

You can also use the syntax ArrayList<char[]>, but this means an ArrayList of char arrays, so that's why you are getting this message.

Regards,

Juliano

Message was edited by:

JulianoAlberto

JulianoAlbertoa at 2007-7-9 5:08:27 > top of Java-index,Java Essentials,Java Programming...
# 2

Generic type parameters can't be primitive types, meaning that you can have List<Integer> but not List<int>. In your case you *could* use the wrapper type Character:

List<Character> list = new ArrayList<Character>();

*However*, you haven't told us why you think you *need* a list of characters. Have you considered StringBuffer/StringBuilder instead?

DrLaszloJamfa at 2007-7-9 5:08:27 > top of Java-index,Java Essentials,Java Programming...