This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Implementing an arraylist using arrays" Watch "Implementing an arraylist using arrays" New topic
Author

Implementing an arraylist using arrays

Sharon Bose
Greenhorn

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
Hi,

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

_steve.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Or use java,util.ArrayList.

Is this homework?


[Jess in Action][AskingGoodQuestions]
Vivek Upadhyay
Greenhorn

Joined: Jul 18, 2005
Posts: 2
Hi,

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
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing an arraylist using arrays