0

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

4
  • What language are you using for this? Commented Apr 19, 2015 at 15:47
  • the language is android Commented Apr 19, 2015 at 15:55
  • 2
    an array has a fixed size and is not dynamic. The closest thing is to use a List instead. Commented Apr 19, 2015 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™. Commented Apr 19, 2015 at 16:02

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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>

1 Comment

Not technically an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.