W
Wendy S
I have a String[] (property of a Struts form bean) that I need to manipulate
in Java code.
I would really prefer to work with an ArrayList to avoid the inevitable out
of bounds errors and having to grow the array, etc.
I thought I had it with Arrays.asList( myArray) but that turns out to not
allow items to be added, it just provides a List backed by a fixed size
array. Is there a way to turn a String[] into an ArrayList, without
looping?
What's the easiest way to add one to the size of a String[] and avoid all
the usual pitfalls?
I have this:
String[] accounts = new String { "one", "two", "three" };
String[] newArray = new String[ accounts.length + 1];
System.arraycopy( accounts, 0, newArray, 0, accounts.length );
newArray[ newArray.length - 1 ] = "four";
accounts = null;
Comments? Suggestions? Thanks!
in Java code.
I would really prefer to work with an ArrayList to avoid the inevitable out
of bounds errors and having to grow the array, etc.
I thought I had it with Arrays.asList( myArray) but that turns out to not
allow items to be added, it just provides a List backed by a fixed size
array. Is there a way to turn a String[] into an ArrayList, without
looping?
What's the easiest way to add one to the size of a String[] and avoid all
the usual pitfalls?
I have this:
String[] accounts = new String { "one", "two", "three" };
String[] newArray = new String[ accounts.length + 1];
System.arraycopy( accounts, 0, newArray, 0, accounts.length );
newArray[ newArray.length - 1 ] = "four";
accounts = null;
Comments? Suggestions? Thanks!