Name: bk70084 Date: 11/03/97
Array resizing is something programmers often need
to do.
Right now, the best way to do it is:
(1) allocate a new array and assign it to a new
temporary variable
(2) using the System.arraycopy method, copy the
elements from the original array into the new
array
(3) assign the handle of the new array to the old
variable
This is tedious.
Would it be cool if an array's "length" property
was writable?
int [] ar = new int [5];
...use ar for a while...
...decide it's time to make it an array of 10 elements...
ar . length = 10;
/* done */
I think this is an interesting idea worth pursuing,
and it would not compromise backward compatibility.
Another alternative is to add a resize () method
to all arrays.
(Review ID: 19257)
======================================================================
- relates to
-
JDK-4848022 Request for dynamic shrinking of built-in array types
-
- Closed
-