This week's book giveaway is in the
Agile and other Processes
forum.
We're giving away four copies of
The Mikado Method
and have Ola Ellnestam and Daniel Brolund on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Changing size of java array
Angela lewis
Ranch Hand
Joined: Mar 01, 2004
Posts: 100
posted
Mar 11, 2004 06:26:00
0
I have an array of Strings . Can i change its size at run time.
Is there a method for this?
john smith
Ranch Hand
Joined: Mar 04, 2004
Posts: 75
posted
Mar 11, 2004 06:37:00
0
No. Array size is fixed at the point of creation. Should you need a list-type collection which can grow, use
ArrayList
instead.
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
13
I like...
posted
Mar 11, 2004 07:24:00
0
While John's answer is technically correct, you can of course allocate a new array and copy the old one over:
String[] smallArray = new String[5]; // decide you need 6 elements, not 5 String[] temp = new String[6]; System.arraycopy(smallArray, 0, temp, 0, smallArray.length); smallArray = temp;
This is often all you really need, and it's actually how
ArrayList
works internally.
[Jess in Action]
[AskingGoodQuestions]
Angela lewis
Ranch Hand
Joined: Mar 01, 2004
Posts: 100
posted
Mar 11, 2004 08:04:00
0
thank you so much.
that was great help
I agree. Here's the link:
http://aspose.com/file-tools
subject: Changing size of java array
Similar Threads
just check this...
about this array class
NullPointerException
Anonymous array
Random number between size of an array
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter