If I don't know the size of array of chars I'm using, is there a way to use it without setting the size upfront ?
2 Answers
In general, you can use a java.util.List when you don't know the size up front.
List<Character> chars = new ArrayList<Character>();
chars.add('f');
chars.add('o');
chars.add('o');
Depending on your needs, a StringBuilder might make more sense than a List<Character>.
StringBuilder sb = new StringBuilder();
sb.append('f')
.append('o')
.append('o');
If you want to get really slick, use Trove for its list-of-primitives so you can work with the (third-party equivalent of) a nevermind. Trove does not have a List<char>.TCharArrayList.