title: Java - Accessing the properties of an object without using the direct field name
body: <p>So for the below question, I tried to search online but I couldn't find the answer to it. I am working in Java language. </p>
  
  <p>So I currently have a class, lets say:</p>
  
  <pre><code>public Employee(String emp_id, String location, String name)
      {
          this.emp_id = emp_id;
          this.location = location;
          this.name = name;
      }
  </code></pre>
  
  <p>I have created multiple objects of Employee, and I have saved it in an arrayList. Now, I the user will ask which employees are located in New York, or they can ask which employees are named John. </p>
  
  <p>So they can enter location New York. I need to read in the user's request, first identify what they are trying to search, and then see if there are any matching Employees in the array. </p>
  
  <p>I have read in the command, and saved it in an array of strings called Search. The first index holds the name of the field/property of the object, and the second index will hold what the user actually wants to check. </p>
  
  <pre><code>String[] search = new String[] { "location", "New York" }
  </code></pre>
  
  <p>I was thinking for doing this:</p>
  
  <pre><code>for(Employee e: empList)
      if(e.search[0].equals(search[1]))
        System.out.println(e)
  </code></pre>
  
  <p>However, I am not able to do this, since <code>search[0]</code> is not a property name for the <code>Employee</code> object. I am getting this error: error: cannot find symbol.</p>
  
  <p>Is there a way for me to access the object property without the actual name, meaning the name is saved in another <code>String</code> variable?</p>
  
  <p>Please let me know. Appreciate your help.</p>
  
  <p>Thank you. </p>