waffe
asked on
Is there an append method for java arrays
Hi,
I have several arrays in java, some ints, some strings etc... I would like to add (append) info to the end of them. How is this done?
Thanks,
waffe
I have several arrays in java, some ints, some strings etc... I would like to add (append) info to the end of them. How is this done?
Thanks,
waffe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks I have been looking into Arraylist and Vectors - running into a few problems but I'll post if I need some help.
Thanks,
waffe
Thanks,
waffe
http://www.javaworld.com/javaworld/jw-08-1999/jw-08-cooltools.html
public int[] method01( SomeContainer rset )
{
int[] bigArray = new int[ 1024 ];
int count = 0;
while( rset.next() )
{
if( count >= bigArray.length ) // time to grow!
{
int[] tmpArray = new int[ bigArray.length + 1024 ];
System.arraycopy( bigArray, 0, tmpArray,
0, bigArray.length );
bigArray = tmpArray;
}
bigArray[ count ] = rset.getInt();
count += 1;
}
int[] smallArray = new int[ count ];
System.arraycopy( bigArray, 0, smallArray, 0, smallArray.length );
return smallArray;
}