[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Setting a variable from an array

Posted on 2005-05-13
8
Medium Priority
?
185 Views
Last Modified: 2006-11-18
What I want to do is loop though the array and when I see 1 particular piece of data I want to set it to a variable. This is what I have so far:
         IServicecallCode1Home bldgHome = session.getServicecallCode1Home();
        //      Find all possible bldgs of service calls.
        IServicecallCode1[] bldgs = bldgHome.findAllServicecallCode1();
        for (int i=0; i<bldgs.length; i++)
                    System.out.println(i + bldgs[i].getText());
                     BufferedReader y = new BufferedReader (new InputStreamReader(System.in));
                     try
                         {
                                 String s = y.readLine();
                                 if (s == "ANY   Unable to determine location")
                                 {
                                    String NewBuilding = s;
                        }
                     catch (Exception e)
                           {

                           }
       sc.setServicecallCode1(NewBuilding);
0
Comment
Question by:malich1
  • 5
  • 2
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13998626
Where does reading the file come in and why do it for every element in the array?
0
 

Author Comment

by:malich1
ID: 13998651
I was just reading the file to see what was where. I need to find the element text of "ANY   Unable to determine location" thats what I really need. then I have to set it in sc.setServicecallCode1(NewBuilding);
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 225 total points
ID: 13998660
I'm guessing this is the overall effect you want ...

for (int i=0; i<bldgs.length; i++) {
      if ("someVal".equals(bldgs[i])) {
            bldgs[i] = "otherVal";
      }
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 13998670
I'm still not sure how you want to connect the array and what's in the file
0
 

Author Comment

by:malich1
ID: 13998718
How would I change the if("somefav".equals(bldgs[i])) to only look for the first 3 characters of the string? something like if("ANY%".LIKE(bldgs[i]))
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13998770
if(bldgs[i] != null && bldgs[i].indexOf("ANY") == 0) {
    // do it
}
0
 
LVL 92

Expert Comment

by:objects
ID: 13999611
use the following:

if (bldgs[i].length()>=3 && "ANY".equals(bldgs[i].substring(0, 3))

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14077515
:-)
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question