• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

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);
0
malich1
Asked:
malich1
  • 5
  • 2
1 Solution
 
CEHJCommented:
Where does reading the file come in and why do it for every element in the array?
0
 
malich1Author Commented:
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
 
CEHJCommented:
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
CEHJCommented:
I'm still not sure how you want to connect the array and what's in the file
0
 
malich1Author Commented:
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
 
CEHJCommented:
if(bldgs[i] != null && bldgs[i].indexOf("ANY") == 0) {
    // do it
}
0
 
objectsCommented:
use the following:

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

0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now