Results 1 to 3 of 3
Thread: Implementation of ArrayList
- 02-10-2013, 07:50 PM #1
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Implementation of ArrayList
I took a class in data structures some time back. In it, I learned that the ArrayList is an array that is just copied into a bigger array when space runs out. But instead of copying everything, even though it happens in amortized constant time, wouldn't it be better to represent it as a doubly linked list of arrays? When it exceeds the current capacity, you can add a new array that's twice as big as the previous one. Or better yet, an ArrayList of arrays, since you can access individual elements with just 2 []/get() operations, and you need to resize the ArrayList much less frequently (and copying comparably fewer elements each time). Of course, it'll make the code for a great deal of operations a bit more complicated, but would the performance benefit be worth it? Are there any reasons not to implement an ArrayList in this way?
Last edited by pifrely; 02-10-2013 at 08:11 PM.
- 02-10-2013, 08:13 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: Implementation of ArrayList
The current ArrayList implementation guarantees the random access is O(1); I don't think a doubly linked list of 'chunks' can do that ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-10-2013, 08:30 PM #3
Member
- Join Date
- Jan 2013
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
ArrayList copy some of the element from one arraylist tnto another arraylist
By ralf in forum New To JavaReplies: 12Last Post: 07-07-2011, 08:49 PM -
copying contents of an ArrayList to another ArrayList
By ankit1801 in forum New To JavaReplies: 8Last Post: 03-27-2011, 06:07 AM -
sorting arraylist based on another arraylist
By busdude in forum New To JavaReplies: 4Last Post: 02-07-2011, 11:48 AM -
how to add Arraylist filter for a jsp page showing results from a servlet-Arraylist
By alok_sharma in forum Java ServletReplies: 7Last Post: 11-22-2010, 01:26 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks