title: Adding multiple objects to ArrayList that match a selected string
body: <p>What I am trying to do: Fill the namesArray with all the objects that match a certain criteria.</p>
  
  <p>The Activity object is made of four strings "category, name, note, time"</p>
  
  <p>The getCategory(activityArray) returns a string which is the selected category, I'm trying to sort the objects where their category matches the selected category into the new namesArray</p>
  
  <p>So this namesArray will end up containing only Activity objects with selected category.</p>
  
  <p>This is my code:</p>
  
  <pre><code> public static void viewActivity(ArrayList&lt;Activity&gt; activityArray) {
        String categ = getCategory(activityArray);
        String holder;
        ArrayList&lt;Activity&gt; namesArray = new ArrayList&lt;Activity&gt;();
        for(Activity obj : activityArray) {
           holder = obj.getCategory();
           if(holder == categ) {
              System.out.println(obj.getName());
              namesArray.add(obj);
           }
        }
  }
  </code></pre>
  
  <p>When I run the debugger, first iteration works, and the first object where it's category matches the selected category is added to the namesArray. But then the if statement just seems to stop working, the holder String does not change and stays the same.</p>
  
  <p>So how do I get my method to add every matching object to the namesArray instead of only the first one? </p>
  
  <p>Thanks</p>