This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes ArrayList performance for Large Objects. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ArrayList performance for Large Objects." Watch "ArrayList performance for Large Objects." New topic
Author

ArrayList performance for Large Objects.

Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.)


[Jess in Action][AskingGoodQuestions]
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

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

Joined: Oct 13, 2005
Posts: 38045
    
  22
There is a method specific to ArrayList which might make adding 5000 elements even faster: here.
Robin John
Ranch Hand

Joined: Sep 10, 2008
Posts: 270

thanks a lot
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList performance for Large Objects.
 
Similar Threads
toArray function of ArrayList
Code to sort and remove duplicates in ArrayList and Hashmap
Copy existing Array into new ArrayList
Passing objects or Vector of objects via HTTP
Pass ArrayList To Oracle