• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

String array

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the question is...??
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a great reply Stephanie, thanks!
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}

}
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!