title: How to compare Object property name to a string?
body: <p>Is there a way to compare if the property in an <code>Object</code> is equal to a string?</p>
  
  <p>Here is a sample Objet named <code>Person</code></p>
  
  <pre><code>public class Person {
  
      private String firstName;
      private String lastName;
  
      public Person(String firstName, String lastName){
          super();
          this.firstName = firstName;
          this.lastName = lastName;
      }
  
      //.... Getter and Setter
  
  }
  </code></pre>
  
  <p>Now I have a method that I need to check if that string is same with the <code>Person</code> property name.</p>
  
  <pre><code>public boolean compareStringToPropertName(List&lt;String&gt; strs, String strToCompare){
      List&lt;Person&gt; persons = new ArrayList&lt;Person&gt;();
      String str = "firstName";
  
      // Now if the Person has a property equal to value of str, 
      // I will store that value to Person.
      for(String str : strs){
  
          //Parse the str to get the firstName and lastName
          String[] strA = str.split(delimeter); //This only an example
  
          if( the condintion if person has a property named strToCompare){
              persons.add(new Person(strA[0], strA[1]));
          }
      }
  
  }
  </code></pre>
  
  <p>My actual problem is far from this, for now how will I know if I need to store the string to a property of the <code>Object</code>. My key as of now is I have another string that same with the property of the object.</p>
  
  <p>I don't want to have a hard code that's why I'm trying to achieve a condition like this.</p>
  
  <p>To summary, Is there a way to know that this string<code>("firstName")</code> has an equal property name to Object<code>(Person)</code>.</p>