Link to home
Start Free TrialLog in
Avatar of malich1
malich1

asked on

Setting a variable from an array

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);
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Where does reading the file come in and why do it for every element in the array?
Avatar of malich1
malich1

ASKER

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);
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'm still not sure how you want to connect the array and what's in the file
Avatar of malich1

ASKER

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]))
if(bldgs[i] != null && bldgs[i].indexOf("ANY") == 0) {
    // do it
}
use the following:

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

:-)