3 Replies - 9968 Views - Last Post: 23 March 2011 - 04:13 AM Rate Topic: -----

#1 Zukky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-March 11

Advantages & Disadvantages of using an ArrayList for holding data?

Posted 22 March 2011 - 09:41 PM

Hi,

I'm new to this forum, just want to say a warm "Hi!" from me first of all ;)!

Anyway, I want to know what are the advantages and disadvantages of using an ArrayList for holding data? Also, instead of using an ArrayList, what difference would it actually make to a program i.e. imagine I have a name class, that registers surname and first name - what difference would it make if I used HashSet or TreeSet to hold the data instead? Would it actually change anything in the program?

Thank you,

Zukky :)

Is This A Good Question/Topic? 0
  • +

Replies To: Advantages & Disadvantages of using an ArrayList for holding data?

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8315
  • View blog
  • Posts: 31,836
  • Joined: 06-March 08

Re: Advantages & Disadvantages of using an ArrayList for holding data?

Posted 22 March 2011 - 09:51 PM

ArrayList have dynamic size which arrays do not have
HashSet do not allow duplicates
LinkedList have more overhead if your set is big, ArrayList directly access an index, LinkedList have to scan node after node

p.s.
and we do not do homeworks :)
Was This Post Helpful? 0
  • +
  • -

#3 Zukky  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-March 11

Re: Advantages & Disadvantages of using an ArrayList for holding data?

Posted 23 March 2011 - 04:10 AM

Thank you, that was helpful! But what are the disadvantages to it?
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10180
  • View blog
  • Posts: 37,585
  • Joined: 27-December 08

Re: Advantages & Disadvantages of using an ArrayList for holding data?

Posted 23 March 2011 - 04:13 AM

Depends what you're trying to accomplish. LinkedLists are great for adding Nodes to the front or back of the list. ArrayLists are better for when you need to work with elements anywhere in the List. Not so much of a pro and con thing, as much as which data structure is better suited to a particular task.

Also, you might want to check out my blog entry An Overview of the Java Collections Framework.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1