Results 1 to 6 of 6
- 11-17-2008, 03:28 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
[SOLVED] Should I use an arraylist or an array?
I was looking at a practice Computer Science AP test today and I came across something I'd never seen before: an arraylist. I'd been using arrays for a while now and when I looked at the description of the array class, I realized that you can do a lot more with an arraylist than an array. So I ask those who are familiar with both, in what general situations would you use an array instead of an arraylist?
- 11-17-2008, 03:48 AM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
An ArrayList is an implementation of the List interface using an array. There is nothing you can do with ArrayList that you can't do with an array, though you would have to implement the methods yourself.
I would only use an ArrayList, or any kind of List, when I can have a variable amount of objects stored in the List, probably based on input.
That's just me, though. I'm sure other people feel differently.
-
Hello matzahboy and welcome.
I would use arrays when I know the size of the collection and I know that it won't change. I'll use arraylist when either of the above are false.
signed MatzahBoySoup.
- 11-17-2008, 03:53 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
That makes sense. Is there a downside to using an arraylist if I do know the size of the collection and I know I won't change it?
BTW... I do love matzah ball soup, but I'm not a cannibal or Michael Jackson, so I won't eat MatzahBOY Soup.
-
If you need to iterate over the collection fast or do operations on it very fast, arrays I believe are faster than arraylists as there's less overhead involved.
I always thought that my mom made the best matzah-ball soup. then I found out she uses a mix from a box.
- 11-17-2008, 04:34 AM #6
Member
- Join Date
- Nov 2008
- Posts
- 67
- Rep Power
- 0
Similar Threads
-
ArrayList versus Array
By junpogi in forum New To JavaReplies: 13Last Post: 11-08-2008, 02:04 AM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
Arraylist to a 2- dimension array conversion
By mars123 in forum New To JavaReplies: 1Last Post: 12-06-2007, 11:24 AM -
Converting ArrayList to Array
By Java Tip in forum Java TipReplies: 0Last Post: 11-13-2007, 10:41 AM -
Array to ArrayList
By javaplus in forum New To JavaReplies: 2Last Post: 11-12-2007, 12:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks