title: Loop through objects fields?
body: <p>I have a class called "Thing" storing the objects of that class in an arraylist, and I am using a for loop to access its' fields. </p>
  
  <pre><code>public class Thing {
      String title;
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  </code></pre>
  
  <p>In the code provided below, the loop is accessing the objects of "Thing" class, one at a time, and hence the count gets incremented always by 1. How would I access the title variable of the object, so that if the title has multiple occurence of the same "word", the count gets incremented accordingly ?</p>
  
  <pre><code>public static String wordCounter(List&lt;Thing&gt; list, String word){
      int count = 0;
      for(Thing thing : list){
          if(thing.getTitle().toLowerCase().contains(word.toLowerCase())){
              count++;
          }
      }
      return word + " appears: " + count;
  }
  </code></pre>
  
  <p>Thanks</p>