title: How do you access the ArrayList attribute of an object when that object is also in an ArrayList?
body: <p>So I have several objects in an ArrayList. Each of these objects have an attribute that is several Strings in an ArrayList. I'm trying to compare the Strings in a separate ArrayList to the ones in an objects' attributes. The problem is- the get method isn't working. Every time I try to use .get().getColors();, it tells me that that method doesn't exist.</p>
  <p>For context, these are the main objects/ArrayLists:</p>
  <pre><code>//fav colors of the two people
  ArrayList list1 = new ArrayList();
  list1.add(&quot;RED&quot;);
  list1.add(&quot;BLUE&quot;);
  list1.add(&quot;GREEN&quot;);
  ArrayList list2 = new ArrayList();
  list2.add(&quot;YELLOW&quot;);
  list2.add(&quot;PURPLE&quot;);
  
  //colors i will compare the people's fav colors to
  ArrayList comparison = new ArrayList();
  comparison.add(&quot;PURPLE&quot;);
  comparison.add(&quot;RED&quot;);
  
  Person p1 = new Person(&quot;Sarah&quot;, 45, list1);
  Person p2 = new Person(&quot;Simone&quot;, 33, list2);
  
  //ArrayList containing the people
  ArrayList bioBook = new ArrayList();
  bioBook.add(p1);
  bioBook.add(p2);
  </code></pre>
  <p>These are the attributes of the Person class as well as the get method:</p>
  <pre><code>private String name;
  private int age;
  private ArrayList favColors;
  
  public ArrayList getColors(){
       return favColors;
  }
  </code></pre>
  <p>And this is what I tried to do. I had the thought of storing the favorite colors of that specific person into another ArrayList so I could compare them. It feels like I'm complicating it, and it tells me specifically that bioBook.get(h).getColors().size() and bioBook.get(h).getColors(g) can't work due to the .getColors() method.</p>
  <pre><code>ArrayList trySmthg = new ArrayList();
  
  //loops through the first ArrayList
      for(int h = 0; h &lt; bioBook.size(); h++){
            //this loops through the ingredients ArrayList of the object
            for(int g = 0; g &lt; bioBook.get(h).getColors().size(); g++){
              tryingSmthg.add(bioBook.get(h).getColors(g));
            }
  
  //this is where i would then compare the two ArrayLists and store how different they are from each other for later use
       
          }
  </code></pre>
  <p>I apologize if this is muddled- this is my first time posting here, and I've tried searching on guides to this, but found nothing.</p>