Results 1 to 6 of 6
  1. #1
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default [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?

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  4. #4
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    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.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  6. #6
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Thanks. Do you know where I could find a tutorial to learn more about arraylists (from a beginner's prospective, since I just found out they existed)?

    Your mom's matzah ball soup is no match for my grandma's!

Similar Threads

  1. ArrayList versus Array
    By junpogi in forum New To Java
    Replies: 13
    Last Post: 11-08-2008, 03:04 AM
  2. Replies: 2
    Last Post: 04-21-2008, 12:43 PM
  3. Arraylist to a 2- dimension array conversion
    By mars123 in forum New To Java
    Replies: 1
    Last Post: 12-06-2007, 12:24 PM
  4. Converting ArrayList to Array
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-13-2007, 11:41 AM
  5. Array to ArrayList
    By javaplus in forum New To Java
    Replies: 2
    Last Post: 11-12-2007, 01:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •