aspose file tools*
The moose likes Java in General and the fly likes String [] Array initialization in a for loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "String [] Array initialization in a for loop" Watch "String [] Array initialization in a for loop" New topic
Author

String [] Array initialization in a for loop

Anurag Mishra
Ranch Hand

Joined: Jun 16, 2003
Posts: 121
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

Joined: Jan 29, 2003
Posts: 8791
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 ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Anurag Mishra
Ranch Hand

Joined: Jun 16, 2003
Posts: 121
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String [] Array initialization in a for loop
 
Similar Threads
Please review my code
How to make combination function generic
need help
anilbachi question?
non-static variable this cannot be referenced from a static context