Implement ArrayList

How do you implement ArrayList without using Collections in Java?

Questions by naveed_osi

Showing Answers 1 - 1 of 1 Answers


  • Oct 30th, 2009

def size=10
def loadfactor=0.75
def myarray = Object[size]
def cursor=0
def threshold = (int)(size * loadfactor)

def add(obj)
    if cursor < threshold
       myarray[cusror++] = obj
       def newarr = Object[size * 2]
       System.arrayCopy (newarr, myarray, 0, myarray.size) // copy over all items to new
       myarray = newarr
       size = size * 2
       threshold = (int)(size * loadfactor)
       myarray[cusror++] = obj

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions