Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes size of array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "size of array" Watch "size of array" New topic
Author

size of array

ming ming
Ranch Hand

Joined: May 17, 2006
Posts: 54
how can i add the size of an array when it reaches it maximum???

vinod balaji
Ranch Hand

Joined: May 18, 2006
Posts: 84
declare the amount variable as static. then it works fine
ming ming
Ranch Hand

Joined: May 17, 2006
Posts: 54
i need to use a loop in the setTest method to make it auto increase the size of the array....but when i use a loop it will only show the first input....
any idea how to solve that?
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
Hi,
first of all, you could take a look how Sun did in the ArrayList source file.
Second, you make another array with for example twice the length of your full array and then you use arraycopy to transfert the data to the new one.

you could also do like that :

I hope it help,
Arno
[ May 26, 2006: Message edited by: Arno Reper ]

The man who makes no mistakes does not usually make anything<br /> <br />>>> SCJP 5.0 >> SCJD B&S <<< In progress
Arno Reper
Ranch Hand

Joined: Mar 14, 2006
Posts: 286
ps : its nicer to write that with a static field...
like :

arno
 
jQuery in Action, 2nd edition
 
subject: size of array
 
Similar Threads
add property of type enum to class
Forgetting about constructors
Java Array search and print
Confused with file read
Class access question