0

I want to declare an array of String whose dimension is not known. How to declare and initialize it ?

greywolf82
  • 21,813
  • 18
  • 54
  • 108
pheromix
  • 18,213
  • 29
  • 88
  • 158

2 Answers2

4

In Java, arrays have fixed size and the length cannot be changed once they are declared.

But as suggested by others, use arraylist. Although the syntax is slightly different, array and arraylist work the same way.

Tutorial

Documentation

Community
  • 1
  • 1
Confuse
  • 5,646
  • 7
  • 36
  • 58
3
List<String> words = new ArrayList<String>();

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

This is a dynamic list of elements <String>

corn3lius
  • 4,857
  • 2
  • 31
  • 36