Implementing an ArrayList as a Primitive Array. Plzzz Help a Newbie!!!

Hi I am a newbie to Java,

I have the following question, could someone please demonstrate some code to answer it?...

Q)

The Java class ArrayList uses a primitve array as its internal data structure and provides methods to access the array elements.

Write a implentation of a basic version of ArrayList providing methods to get, set, insert and delete elements. It should be possible to insert and delete at any position within the ArrayList. The methods should throw exceptions as necessary. Include one or more appropriate constructors.

Thanks in advance

Carl

[605 byte] By [carlos2006a] at [2007-10-2 20:15:35]
# 1

> Hi I am a newbie to Java,

> I have the following question, could someone please

> demonstrate some code to answer it?...

>

> Q)

>

> The Java class ArrayList uses a primitve array as its

> internal data structure and provides methods to

> access the array elements.

> Write a implentation of a basic version of ArrayList

> providing methods to get, set, insert and delete

> elements. It should be possible to insert and delete

> at any position within the ArrayList. The methods

> should throw exceptions as necessary. Include one or

> more appropriate constructors.

>

>

> Thanks in advance

>

> Carl

No it doesn't. It uses an object array. The question itself demonstrates that the author was either sleepy or not very knowledgeable to begin with as they either consider an array of objects a "primitive array" or they think all arrays are primitives.

Regardless, what I suspect they want from you is more or less a Collection backed by an array. For an example of one look at ArrayList's source code to begin with.

kablaira at 2007-7-13 22:57:54 > top of Java-index,Core,Core APIs...