File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String array" Watch "String array" New topic

String array

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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.
[This message has been edited by avn (edited August 05, 2000).]
Tony Alicea

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

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
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.

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

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) {
// 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
Here is the code you requested:

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

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.
Ed Parks

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.
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
if (array[i].secondString == null){
// process second string

I agree. Here's the link:
subject: String array
Similar Threads
Casting question
Javascript string array to server
String to Object array
casting an object array to string array