Differences between String[] and listArray<String>

10,149

Solution 1

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.

Solution 2

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.

Solution 3

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

Share:
10,149
HeikiCyan
Author by

HeikiCyan

Updated on June 14, 2022

Comments

  • HeikiCyan
    HeikiCyan almost 2 years

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

  • HeikiCyan
    HeikiCyan over 11 years
    does it mean that both String[] and ArrayList<String> store the same type data?
  • Ahmad
    Ahmad over 11 years
    @HeikiCyan In this case both store Strings.
  • cammando
    cammando about 7 years
    Which is more efficient