title: Searching for a specific object in an ArrayList Java
body: <p>I am trying to find a specific object based on user input. The user is to enter a name and a gender and then the program is supposed to search an ArrayList and see if there is a name and gender that matches. The object in the ArrayList has 3 instance variables, but the program only searches for 2. How can I search for only a select few characteristics in an ArrayList?</p>
  
  <p>In my program I have:</p>
  
  <pre><code>int nameListLength = nameList.size();
     .
     .
     .
  
  boolean done = false;
  while (!done) {
     System.out.println ("Please enter a name:");
     String searchName = input.nextLine();
     if (searchName.equals("DONE")) {
        done = true;
     } else {
        System.out.println ("Please enter a gender:");
        String searchGender = input.nextLine();
        // Search the ArrayList.
        for (int i = 0; i &lt; nameListLength; i++) {
           // See if the gender is in the ArrayList
           if (searchGender.equals(nameList.get(i).getGender())) {
              // See if the name matches the gender in the ArrayList
              if (searchName.equals(nameList.get(i).getName())) {
                 System.out.println ("Match found");
              }
           }
        }
     }
  }
  </code></pre>
  
  <p>Where nameList is the name of the ArrayList, getName() is the name of the method that returns the name stored in the object, and getGender() is the name of the method that returns the gender stored in the object. I put in debug statements to determine that the ArrayList is stoing the information correctly, I'm just having problems figuring out how to search for what I am looking for. I know there is a contains(Object o) method, but I am not sure if I can implement that here since I only need to match 2 characteristics of the object even though the object contains 3 pieces of data.</p>