• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

difference between array and arraylist

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I confused abt array and arraylist difference.
pls send to me.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic