Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Tolls

Thread: Advantage of arraylist over array

  1. #1
    karang is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Advantage of arraylist over array

    Hi


    I have listed some points about advantage of arraylist over array

    1. An array is type specific i.e. one array can only store data of only one data type where as arraylist can store multiple data in the form of objects. So multiple objects of different data types can be stored in arraylist.

    2. In array you cannot increase or decrease the size dynamically where as in arraylist the size can be increased or decreased dynamically

    3. You can make arraylist readonly.

    4. You can insert element at any location in arraylist

    5. Arraylist supports BinarySearch

    6. ArrayLists implement iterable , which means you can easily iterate them.

    7. if an arraylist is modifed by another thread while it is being iterated by one thread , then it fails fast , which means you don't end up with unreliable data in the list.


    Please let me know if the points are correct and please suggest me if there are some more points I can add.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Advantage of arraylist over array

    1. Object[]? That's no different to an untyped ArratList. And I really would not say lack of type-specificity was an advantage. There's a reason generics were added to the language.

    3. You can do that with an array, and in exactly the same way. By wrapping it in a class that errors on/does not have an add() method.

    I'm not too sure about 6, with the for-each syntax these days.
    karang likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Advantage of arraylist over array

    Last edited by DarrylBurke; 09-25-2012 at 03:55 PM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    karang is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: Advantage of arraylist over array

    Hi Tolls

    Your post solved my problem thanks a lot :)

Similar Threads

  1. What is advantage of interface in java?Plz help
    By Eyeinstyin in forum New To Java
    Replies: 13
    Last Post: 09-08-2011, 02:12 AM
  2. advantage of jaxp over dom and sax parser
    By javastuden in forum New To Java
    Replies: 0
    Last Post: 10-08-2010, 07:31 AM
  3. advantage of using thread
    By simorgh in forum Threads and Synchronization
    Replies: 3
    Last Post: 02-18-2010, 06:53 AM
  4. Advantage of Using Interface Over Class.
    By makpandian in forum New To Java
    Replies: 5
    Last Post: 06-08-2009, 12:58 PM
  5. Replies: 7
    Last Post: 09-16-2008, 07:20 PM

Posting Permissions

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