How would you create an array list with booleans and chars, not strings or integers?
You can't do it using static typing. The Java type system doesn't allow it.
The best you could do is to implement a List
class that checks the type of the elements that it is puting into the list. (You could extend ArrayList
and override the methods that add or modify list elements.)
Tom's answer is another way to achieve this, at the cost of an extra wrapper object for each list element. This avoids the need for a typecast on extraction, but you could do that by adding getInt(pos) and getChar(pos) methods to the custom list class.