Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between array and arraylist

 
ravi yandluri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I confused abt array and arraylist difference.
pls send to me.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Richards
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another difference is that an array has "special" syntax to access its elements. For an ArrayList, use methods just like other objects.

Layne
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic