title: Using user input for searching object in java
body: <p>When creating e.g an address book I also want a method for searching it.
  Imagine I go for an object like this:</p>
  <pre><code>public class someone {
  
  private static someone [] addressBook = new someone[150];
  private String firstName;
  private String lastName;
  private String address;
      //...
  
  public someone(String firstName, String lastNameame, String adress/*,...*/){
      this.firstName=firstName;
              //...
  }
  </code></pre>
  <p>Now I'm planning on searching for someone using user input and Scanner. First, the user should declare for what (s)he is searching in gerneral:</p>
  <pre><code>public static void searchSomeone(){
  
  System.out.println(&quot;What do you want to search for?: &quot;);
  Scanner sc1 = new Scanner(System.in);
  String userInput1 = sc1.next(); // e.g. userInput1=&quot;firstName&quot;
  </code></pre>
  <p>Second, the user is asked for the exact value (s)he is searching for:</p>
  <pre><code>System.out.println(&quot;Enter a &quot; + userInput1 + &quot;: &quot;);
  Scanner sc2 = new Scanner(System.in);
  String userInput2 = sc2.next(); // e.g. userInput2=&quot;Peter&quot;  
  
      for (int i=1;i&lt;150;++i){
              if(getAddressBook[i].**&quot;Value of userInput1&quot;**.contains(userInput2)){ // here is my problem!*
                      System.out.println(&quot;Congrats, we've found someone! &quot;);
          }
      }
  }
  </code></pre>
  <ul>
  <li>Is there a way to use the value of the input as a call for the member variable?</li>
  </ul>
  <p>In this case the argument should 'become'</p>
  <pre><code>if(getAddressBook[i].firstName.contains(userInput2)){}
  </code></pre>
  <p>I tried to implement another method like getInputValue that simply returns the String but it didn't work here.
  If there is no such solution I will have to include code for every member variable separately which I really dont want to!</p>
  <p>Hope you get my idea! And please be kind I'm quite new to forums. :P</p>