title: Find if in a list of a class defined by me exists an element with given variables values
body: <p>I have defined the class User:</p>
  
  <pre><code>    public class User
      {
          public String id;
          public String passWord;
  
          public User(String id, String passWord)
          {
              this.id = id;
              this.passWord = passWord;
          }
      }
  </code></pre>
  
  <p>Then I created a list of Users:</p>
  
  <p>public static void main(String[] args)
      {</p>
  
  <pre><code>    List&lt;User&gt; users = new ArrayList&lt;User&gt;();
      users.add(new User("u1", "abc"));
      users.add(new User("u2", "aaa"));
      users.add(new User("u3", "bba"));
  </code></pre>
  
  <p>To find the user in the list with a given id and password I did:</p>
  
  <pre><code>Scanner input = new Scanner(System.in);
  System.out.print("User: ");
  String user = input.next();
  System.out.print("Password: ");
  String pass = input.next();
  int N = -1;
  for (int n = 0; n &lt; medicos.size(); n++)
  {
      if (user.equals(users.get(n).id) &amp;&amp; pass.equals(users.get(n).passWord))
          {
              N = n;
          }
      }
  </code></pre>
  
  <p>Is there a simpler way to get the element of the list containing the given id and password, for example like using a method similar to contain?</p>