vbGore Free Online RPG Engine

Revolutionizing Visual Basic ORPG Development
It is currently Sat May 25, 2013 3:15 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Java string array
PostPosted: Wed Jan 06, 2010 6:41 pm 
Wizard of Xor

Joined: Tue Mar 17, 2009 3:48 pm
Posts: 238
I want to add a string array to a java application, but I can't figure out how to initialize it.

I want it to have a number of dimensions defined by a variable, such as

(vb6 form)
Code:
For i = 1 to MyInt
  MyArr(i) = ""
Next


But I can't figure how to initialize it so that I can use it later, putting actual values in each dimension of the array. It will have several dimensions, so I'd rather not initialize it manually. Any suggestions?


Top
 Profile  
 
 Post subject: Re: Java string array
PostPosted: Wed Jan 06, 2010 9:32 pm 
Illegal Operation

Joined: Sun Jun 07, 2009 3:09 pm
Posts: 417
Location: poririn-poriri-pori-pororocca
Standard
String strings[] = new String[100];

strings[1] = 'blah';

Anonymous
String strings[] = new String {'one', 'two', 'three'}

Jagged array
String strings[][] = new String[100][];

for (int i = 0, i < strings.length; i++)
{
strings[i] = new String[10];
}


You will probably get a null error if the element hasn't been assigned a value.

Easy way to bypass this is

for (int i = 0, i < strings.length; i++)
{
if(strings[i] != null)
{
//do stuff
}
}


Top
 Profile  
 
 Post subject: Re: Java string array
PostPosted: Sun Jan 10, 2010 7:41 pm 
Wizard of Xor

Joined: Tue Mar 17, 2009 3:48 pm
Posts: 238
Thanks :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group