Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

infinite array ?

Status
Not open for further replies.

9anth3r

ISP
Sep 3, 2002
7
US
Not sure "infinite array" would be the right term but,

Is there away to define an array of unspecified size ?

Say if i need to store a bunch of int's in an array, but i and the user thats going to enter them doesn't know how many there is going to be. I guess i just don't wanna waste the memory by using a big partially filled array.

Please ignore my ignorance, im still very new to java.
Flo
 
An array is by definition of specified size, because at declaration time, memory is reserved. If you want one that grows or shrinks in size as and when you need, look at the class java.util.Vector or java.util.ArrayList.

(The only diff really being that Vector is synchronized, and ArrayList is not. Use ArrayList unless many different threads are modifying the contents of your array simultaneously).
 
by using ArrayList, you can use trimSize() method to trim down your ArrayList - after you fill in the array with int's
data.


~za~
You can't bring back a dead thread!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top