title: Way to return the name with an element in java?
body: <p>Beginner in Java, I look for the way to return with my function "readPeople ()" the name associated in my ArrayList "this.list" thanks to id given by the user.
  Here is my code:</p>
  
  <pre><code>public class PersonneC implements PersonneDB {
      this.list = new ArrayList();
  
      People marie = new People(1, "Bower", "Marie");
      list.add(marie.toString());
  
        public PeopleWithId readPeople(int idPeople) {
          PeopleWithId peoplename = null;
          for(int i = 0; i &lt; list.size(); i++) {
              if(liste.get(i).equals(idPeople)) {
                  result = list.get(i);
              }
          }
          return result.getPeopleName(); //ERROR INCOMPATIBLE TYPES
          }
  </code></pre>
  
  <blockquote>
    <p>Wanted result returned: Bower</p>
  </blockquote>