Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList performance for Large Objects.

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want to confirm one thing about performance of arraylist.

I have to read a file and get 5000 objects containing two strings each.. and pass it on... I am currently using an ArrayList to pass the objects to the next level.. i wanted to know should i go ahead using ArrayList.?? please advice.. will it be a problem with Heap Space / Memory...

Thanks in advance..

Regards.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ArrayList is very efficient in terms of storage. It's also very efficient if you need to iterate over the list items in order. It's very inefficient, however, at adding or deleting items from the beginnng or the middle of the list, in which case LinkedList is better (of course, LinkedList uses much more memory per element.)
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much! i will go ahead then i dont have adding and deleting requirements

i cant believe i got a reply from you Ernest...

Regards.
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a method specific to ArrayList which might make adding 5000 elements even faster: here.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic