Article View: borland.public.jbuilder.java.language
Article #8710Re: Declaring an Array of Strings?
From: Thomas682
Date: Thu, 08 Mar 2001 19:54
Date: Thu, 08 Mar 2001 19:54
73 lines
2859 bytes
2859 bytes
hi,
thanks for your answer - but i donοΏ½t know the
size of the array !
dynamic array resizeing ?
(like VC++ or VB)
MFG
Thomas
"Marcel Gabi" <mgabi@borland.com> wrote in message
news:3AA7C6C2.8F36FA7F@borland.com...
> You have to assign the actual array first.
> What you actually have now is only a reference
> to a string array which has not yet been initialized.
> You can initialize an array by doing the following:
> String[] myArray = new String[size]; wher size is the
> size of the array.
> Or you can also fill up the array directly by doing
> this:
> String[] addressLine = {"0", "1", "2", "3", "4", "5", "6"};
>
> Here is your code snippet again.
> String[] addressLine = new String[7]; //the size is 7
> for(int i=0; i<7; i++){
> addressLine[i]= new String("xxx" + i);
> }
> //print out the content of the array
> for(int j=0; j<7; j++){
> System.err.println(addressLine[j]);
> }
>
> Regards,
>
> Marcel
>
>
> Thomas682 wrote:
>
> > hi,
> >
> > String AddressLine[];
> >
> > for(int i=0;i<7;i++)
> > AddressLine[i]= new String("xxx");
> >
> > no compile error but runtime exception-(Not exists)
> >
> > hmmmmm - Malloc( ?????
> >
> > Thanks for Help
> >
> > Thomas
> >
> > "Tor Iver Wilhelmsen" <tor.wilhelmsen@sds.no> wrote in message
> > news:uu254bq17.fsf@sds.no...
> > > "Harry Whitehouse" <harry@envmgr.com> writes:
> > >
> > > > String AddressLine[];
> > >
> > > Note that this only declares the reference, it does not assign an
> > > actual array to it.
> > >
> > > > for(int i=0;i<7;i++)
> > > > AddressLine[i]= new String; // line 208
> > >
> > > Unlike C++ and C#, constructors in Java need a parenthesis also when
> > > there are no arguments to the constructor. Also, String doesn't have a
> > > no-args constructor, so you need an argument.
>
Technical Details
Message-ID:
<3aa7d567$1_2@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.uni2.dk!newssuck.uni2.dk!bornews.borland.com!dnews!212.211.74.47References:
<3aa6df5f$1_2@dnews> <uu254bq17.fsf@sds.no> <3aa7a736_2@dnews> <3AA7C6C2.8F36FA7F@borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f74b3,9324d780b1c839d2 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-03-08 11:04:10 PST From: "Thomas682" <SchwendnerThomas@Compuserve.com> Newsgroups: borland.public.jbuilder.java.language References: <3aa6df5f$1_2@dnews> <uu254bq17.fsf@sds.no> <3aa7a736_2@dnews> <3AA7C6C2.8F36FA7F@borland.com> Subject: Re: Declaring an Array of Strings? Date: Thu, 8 Mar 2001 19:54:10 -0000 Lines: 75 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 212.211.74.47 Message-ID: <3aa7d567$1_2@dnews> X-Trace: 8 Mar 2001 10:54:31 -0800, 212.211.74.47 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsswitch.lcs.mit.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.uni2.dk!newssuck.uni2.dk!bornews.borland.com!dnews!212.211.74.47