File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Array or ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array or ArrayList" Watch "Array or ArrayList" New topic

Array or ArrayList

Amit Chohan

Joined: Oct 31, 2002
Posts: 29
What are the main differences between an Array and an ArrayList?

Java Junior<br />Leicester<br />England
Phil Lesh

Joined: Oct 16, 2002
Posts: 17
As seen in java api [documentation] about ArrayList: "Resizable-array implementation of the List interface. Implements all optional list operations, and permits all
elements, including null. In addition to implementing the List interface, this class provides methods to
manipulate the size of the array that is used internally to store the list. (This class is roughly equivalent to
Vector, except that it is unsynchronized.)"
To find out more, go here and in the left hand column select the class you want to find more about, i.e. ArrayList.
Hope this helps.
Bert Bates

Joined: Oct 14, 2002
Posts: 8898
Amit and Phil -
Maybe in more human terms:
1) ArrayLists are growable
2) ArrayLists can hold heterogeneous objects (mix and match)
3) Most of the 'modern' collections have stopped imbedding synchronized methods - not having them is no biggie -
4) ArrayLists have cool built-in methods that arrays wish they had:
- isEmpty
- contains
- clear
- remove
these methods make ArrayLists a lot easier and more fun to deal with than arrays.
p.s. Phil - given my signoff it's inevitable...
you didn't used to play in a band in the S.F. area did you

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
It is sorta covered in the JavaRanch Style Guide.
subject: Array or ArrayList
It's not a secret anymore!