Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String [] Array initialization in a for loop

 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI pls see the code,
String tempArray[] = new String[Array.length];//Line 1
for (int i = 0; i < inDate.length; i++) {
// tempArray[i]=""; // WILL THIS WORK inside for loop// Line 2
tempArray[i] += Integer.toString(month+1);
tempArray[i] += "/";

}
I have created an String[] tempArray[] in Line it is initialized to null
But inside this for Loop i want to initialize tempArray[] =""
How it can be done in this
will this work
tempArray[i]=""; inside for loop as in Line 2
thanks
Anurag
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The common form for this is:

which upon reflection, looks almost exactly like your example. Is this not working for you? The only thing funny in your code was initializing the size of the array ... you'll need to get a good number in the size. SOmething like:

The reason yours looked odd was the Array.length. Array is a class, not an instance of an array.
[ December 02, 2003: Message edited by: Stan James ]
 
Anurag Mishra
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
thanks a lot, I was thinking that would be write but could't chk yesterday so posted there.
The Array which i mentioned is just to tell its an array.
anyway thanks a lot its working.
regards
Anurag
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic