char ret[] = {};
Doesn't work seem to work and I'm not sure what the best way to do this is.
Any help would be greatly appreciated.
Arrays must have a fixed length.
If your goal is to have a dynamically expansible list, consider a List instead. Everytime you add an item by add() method, it will grow dynamically whenever needed.
List<Character> chars = new ArrayList<>();
// ...
The best way to have an extensible array of char without the overhead of an Character object for each char, is to use a StringBuilder. This allows you to build an array of char in a wide variety of ways. Once you are finished you can use getChars() to extract a copy of the char[].
You probably come from PHP or another programming language that hasn't got real arrays. (An array in PHP is a sort of dictionary/hashmap)
Arrays in JAVA are fixed length.
For no fixed length, you can use a Vector. If you want to index with something else than integers from 0 to length, you can use a Dictionary.
Vector is a legacy class which was replaced in Java 1.2 (1998) by List Similarly Dictionary was replaced by Map. In the Javadoc for Dictionary it states NOTE: This class is obsolete. New implementations should implement the Map interface, rather than extending this class.
specified lengthmeans dynamic length, you should set the length with a variable. So the length will not be fixed by constant value, while it will be set at runtime.char[] ret = new char[size]. The size will be set at runtime.