jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Implementing an arraylist using arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Implementing an arraylist using arrays" Watch "Implementing an arraylist using arrays" New topic

Implementing an arraylist using arrays

Sharon Bose

Joined: Jul 19, 2005
Posts: 4
can any one explain how to implement an arraylist using arrays
or how to create an array with variying size
Steve Simon Joseph Fernandez
Ranch Hand

Joined: Jul 17, 2005
Posts: 35

Solution 1: provide your own interface and implementation
Solution 2: look at java.lang.reflect.Array

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Or use java,util.ArrayList.

Is this homework?

[Jess in Action][AskingGoodQuestions]
Vivek Upadhyay

Joined: Jul 18, 2005
Posts: 2

If I m not wrong then
U can create a varying size aray by implementing yr own interface.
Also a very easy way to do this is use of vector defined in collection framework.
M I correct?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Originally posted by Vivek Upadhyay:

M I correct?

Not so much. You shouldn't use Vector in new code; ArrayList is intended as a replacement.

Have a look here for information about posting on JavaRanch.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Vivek - please read this.
Sharon - The Java ArrayList and similar collections are implemented using an array that "grows" as needed. Why not take a look at the source for the java.util classes for the details. Sun now expects you to sign a license to download the source but it is still free.
I agree. Here's the link: http://aspose.com/file-tools
subject: Implementing an arraylist using arrays
It's not a secret anymore!