10

Like the title, I would like to know the differences between String[] and ListArray[String], are they same to some extent.

1
  • 1
    Looks similar to this question. Don't let the question title fool you, the intent of the asker seemed to be "Difference between String[] and ArrayList<String>" Commented Dec 1, 2012 at 22:14

3 Answers 3

21

An array String[] cannot expand its size. You can initialize it once giving it a permanent size:

String[] myStringArray = new String[20]();
myStringArray[0] = "Test";

An ArrayList<String> is variable in size. You can add and remove items dynamically:

ArrayList<String> myStringArrayList = new ArrayList<String>();
myStringArrayList.add("Test");
myStringArrayList.remove(0);

Furthermore, you can sort, clear, addall, and a lot more functions you can use while using an ArrayList.

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

3 Comments

does it mean that both String[] and ArrayList<String> store the same type data?
@HeikiCyan In this case both store Strings.
Which is more efficient
10

String[] is an array of Strings while ArrayList is a generic class which takes different types of objects (here it takes Strings). Therefore you can only perform normal array operations with String[]. However, you can use additional, convenient utilities such as isEmpty(), iterator, etc with ArrayList since it also implements Collection Interface.

Comments

3

ArrayList has some neat methods, such as add(), remove(), contains()

Comments

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.