1

I am familiar with using arrays but recently came across ArrayList and was wondering if you would typically use ArrayList more than just a regular Array?

For reference an ArrayList looks like :

ArrayList<Dog> myDogArrayList = new ArrayList<Dog>(); 

Regular Array:

String [] Dog = new String(type) 
1
  • If you Need Features of a Collection, possibility of growing or such Things I would stick to arraylist. Note that ArrayList is "something more" than an array therefor usage Night differ Commented Jul 8, 2015 at 19:59

1 Answer 1

1

ArrayLists (or, in general, the Collections) are intended for heavy read and write operation without thinking too much about capacity, extension and so forth (in the first place). It is much more comfortable to call ArrayList#add than creating a new array with size oldArray.length + 1, doing a System.arraycopy and adding then the element. There are lots of handy methods (indexOf, remove, sublist) which leverage the complexity of use in comparison to arrays.

If you take a look at the Collections class, you'll find a lot of convenience methods like shuffle or reverse.

The use of List in general is much more common than arrays, except you're heading for performance.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.