wood burning stoves*
The moose likes Java in General and the fly likes difference between array and arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "difference between array and arraylist" Watch "difference between array and arraylist" New topic
Author

difference between array and arraylist

ravi yandluri
Greenhorn

Joined: Jan 27, 2006
Posts: 1
Hi All,

I confused abt array and arraylist difference.
pls send to me.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Arrays: http://java.sun.com/docs/books/tutorial/java/data/arrays.html
ArrayList and other collections: http://java.sun.com/docs/books/tutorial/collections/index.html


There is no emoticon for what I am feeling!
Adam Richards
Ranch Hand

Joined: Nov 03, 2005
Posts: 135
The bottom line is that an ArrayList can grow and shrink dynamically, at runtime. Arrays cannot. Once you define an array at compile time, it stays the same size forever. The tradeoff is that arrays can be faster, depending on what your code does.
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
Originally posted by Adam Richards:
The bottom line is that an ArrayList can grow and shrink dynamically, at runtime. Arrays cannot. Once you define an array at compile time, it stays the same size forever. The tradeoff is that arrays can be faster, depending on what your code does.


To say that "structure A is faster/slower than structure B" is never true.
To say that "function F on structure A is faster/slower than structure B" may or may not be true.
To say that "function F on arrays is faster than ArrayList" is never true for all F.

This is a red herring.


Tony Morris
Java Q&A (FAQ, Trivia)
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Another difference is that an array has "special" syntax to access its elements. For an ArrayList, use methods just like other objects.

Layne


Java API Documentation
The Java Tutorial
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Furthermore, in 1.5 an ArrayList like any other Collection is generic and can be used with parameterized types. An array can't, at least not without unchecked casts. Plus, an ArrayList can be used anywhere a List or Collection is declared whereas an array cannot.

It's name is exactly what it is. A List implemented using an array.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between array and arraylist