aspose file tools*
The moose likes Beginning Java and the fly likes String array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String array" Watch "String array" New topic
Author

String array

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
Anyone pl.give me an example for the below statement:I couldnot
follow it.
Suppose there is a loop that is processing an array of items
that each contains 2 string references.The first string is always nonnull,but the second may not not be.To process this.
Thanks!
[This message has been edited by avn (edited August 05, 2000).]
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
And the question is...??


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The question is:To check the notnull values in both the
string references and print them.Actually this is an example
given in RHE for explaining continue; in Loops & Exceptions.
thanks!

bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
Are you saying that you have a array of 2 strings and the first string will always have a value, but the second string may or may not have a value. You then want to run through the array and print out the value if it has one.
Claude Rouleau
Greenhorn

Joined: Oct 13, 2000
Posts: 9
The actual example is in RBE book.
for (int i = 0; i < array.lenght; i++) {
// process first string
if (array[i].secondString == null) {
continue;
}
// process second string
}
I don't understand it and the code is not completed. Can someone complete the code? This will help me to understand.
Merci d'avance.
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
Claude,
Here is the code you requested:

Hope it helps.
Stephanie
[This message has been edited by Stephanie Grasson (edited October 19, 2000).]
Claude Rouleau
Greenhorn

Joined: Oct 13, 2000
Posts: 9
Thanks ! I have taken the time to review the answer and now I understand. I appreciate that you have took time to answer.
Merci
Claude
Ed Parks
Greenhorn

Joined: Oct 31, 2000
Posts: 5
That's a great reply Stephanie, thanks!
Jaydeep Singh
Ranch Hand

Joined: Oct 02, 2000
Posts: 43
Hi Stephanie,
Thanks for your great answer, everything is correct here, I am not clear about, class concept, I have modified your code very little and compile it gives, the same result, so if could explain, that in what situation what is good, what is wrong.

Thanks a lot.
Jaydeep
class TwoStrings{
String firstString;
String secondString;
TwoStrings(String s1, String s2){
firstString = s1;
secondString = s2;
}
//}
//public class Test{
public static void main(String args[]){
TwoStrings array[] = new TwoStrings[5];
array[0] = new TwoStrings("one", "I'm the first string.");
array[1] = new TwoStrings("two", "I'm the second string.");
array[2] = new TwoStrings("three", null);
array[3] = new TwoStrings("four", "I'm the fourth string.");
array[4] = new TwoStrings("five", null);
for (int i = 0; i < array.length; i++){
// process first string
System.out.println(array[i].firstString);
if (array[i].secondString == null){
continue;
}
// process second string
System.out.println(array[i].secondString);
}
}

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String array