I want to declare an array
of String
whose dimension
is not known. How to declare and initialize it ?
Asked
Active
Viewed 81 times
0

greywolf82
- 21,813
- 18
- 54
- 108

pheromix
- 18,213
- 29
- 88
- 158
-
What language are you using for this? – leumas95 Apr 19 '15 at 15:47
-
the language is android – pheromix Apr 19 '15 at 15:55
-
2an array has a fixed size and is not dynamic. The closest thing is to use a `List` instead. – Peter Lawrey Apr 19 '15 at 15:57
-
1@pheromix android is the platform, not the language. Java is the official language used for android but there are other ways such as using Apache Cordova™. – leumas95 Apr 19 '15 at 16:02
2 Answers
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.
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