Bookmark Topic Watch Topic
  • New Topic

Implementation of ArrayList  RSS feed

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can Anyone tell me how the arraylist is implemented internally.It cannot be Array of objects because Arrays occupy spaces at runtime only.And adding a new element automatically shifts other element.I wonder how this could be done.Can Anyone help??
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
From the ArrayList.java file:

Did you install the Java source code with your JDK? Look in your JDK directory for a src.zip file. Unzip it and look for yourself (I'd post it, but ArrayList.java is 21k. So internally, it is an array. If the array is full and you add an element, it creates a new array and copies the entries over. If you insert in the middle, it shifts the entries down and inserts.
There are performance problems with such a structure, which is why there's such a thing as LinkedList, which is more efficient for insert operations.
 
Remaan Rem
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Report post to moderator

Hi,

I think am having the issue with my HW. I am trying to make a class based on the array-based class.
And, I am confused about the use of array. If I create a new array how am going to use it ?
 
Janeice DelVecchio
Bartender
Posts: 1812
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
Welcome to JavaRanch, Ramaan.

Unfortunately, you've chosen a two year old thread to reply to and ask a new question. You'll probably get more replies if you start a new thread.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator

Agreed. Please start a new topic for a new question.

Henry
 
Campbell Ritchie
Marshal
Posts: 55781
164
  • Mark post as helpful
  • send pies
  • Report post to moderator
Agree with Henry and Janeice, but I am feeling more assertive. Asking a new question on somebody else's thread is hi-jacking, so I shall close this thread.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!