[3828] in java-interest

home help back first fref pref prev next nref lref last post

Re: arrays

daemon@ATHENA.MIT.EDU (Pat Niemeyer)
Wed Nov 29 01:56:39 1995

Date: Tue, 28 Nov 1995 22:54:34 -0600 (CST)
From: Pat Niemeyer <pat@icon-stl.net>
To: chwright@goesser.mit.edu
cc: java-interest@java.sun.com
In-Reply-To: <9511282211.AA11783@goesser.mit.edu>


On Tue, 28 Nov 1995 chwright@goesser.mit.edu wrote:

> Say  I have a class with an instance variable that's an array.  Then I 
> go to use the class, but I find I need a larger array than I initialized
> in my class definition.  What do I do??

You probably shouldn't initialize the array in the declaration.

However you can always start over:

        String [] foo = new String [8];

        //...
        // Doh!

        // Double the size of the foo array
        String [] tmpVar = new String [ 2 * foo.length ];
        System.arraycopy( foo, 0, tmpVar, 0, foo.length );
        foo = tmpVar;  

Pat
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post