title: Arraylist - Resort Rental
body: <p>When the user enters the id and resort code, how can I search in the ArrayList and get the array number that the id and resort code are stored in? I'm using a for loop.  </p>
  
  <pre><code>for(Person pe: guestList)
  {
      if ( pe.getPersonId().equals(Id))   
          System.out.println(pe.toString());
  }
  
  for(Resort re: resortList)
  {
      if ( re.getResortCode().equals(resortCode)) 
          System.out.println(re.toString());
  }
  </code></pre>
  
  <p>Instead of manual input: </p>
  
  <pre><code>Rental r1 = new Rental(guestList.get(2),resortList.get(3));
  </code></pre>
  
  <p>Below is my full program. </p>
  
  <pre><code>//create list of resort;
  Chalet c1 = new Chalet("001","chalet1",90);
  Chalet c2 = new Chalet("002","chalet2",90);
  Chalet c3 = new Chalet("003","chalet3",85);
  Chalet c4 = new Chalet("004","chalet4",80);
  Chalet c5 = new Chalet("005","chalet5",80);
  Chalet c6 = new Chalet("006","chalet6",70);
  
  ArrayList &lt;Resort&gt; resortList = new ArrayList&lt;Resort&gt;();
  resortList.add(c1);
  resortList.add(c2);
  resortList.add(c3);
  resortList.add(c4);
  resortList.add(c5);
  resortList.add(c6);
  
  
  //create list of guest
  Person p1 = new Person("001","Alvin","88889999");
  Person p2 = new Person("002","Bob","89889999");
  Person p3 = new Person("003","Wendy ","98123456");
  
  ArrayList &lt;Person&gt; guestList = new ArrayList&lt;Person&gt;();
  guestList.add(p1);
  guestList.add(p2);
  guestList.add(p3);
  
  Scanner console = new Scanner(System.in);
  
  while(true){
  
      System.out.print("Enter your id: ");
      String id = console.nextLine();
      for(Person pe: guestList)
      {
          if ( pe.getPersonId().equals(id))
              System.out.println(pe.toString());
  
      }
  
  
  
      System.out.print("Enter resort code: ");
      String resortCode = console.nextLine();
      for(Resort re: resortList)
      {
          if ( re.getResortCode().equals(resortCode))
              System.out.println(re.toString());
  
      }
  
      Rental r1 = new Rental(guestList.get(2),resortList.get(3));
      System.out.println("");
      System.out.println(r1);
      System.out.println("");
      console.nextLine();
  }
  </code></pre>
  
  <p>Thanks very much for Jason C's Solution. I done with my program.</p>
  
  <pre><code>    int guestIndex = -1; 
  
      for(int i = 0; i &lt;guestList.size(); ++ i)
      {
          if ( guestList.get(i).getPersonId().equals(id)) {
  
            guestIndex = i;
          }
       }
  
  
      int resortIndex = -1; 
      for(int n = 0; n &lt; resortList.size(); ++ n)
      {
        if ( resortList.get(n).getResortCode().equals(resortCode)) {
            System.out.println(re.toString());
            resortIndex = n; 
         }
      }
  
      Rental r1 = new Rental(guestList.get(guestIndex),resortList.get(resortIndex));
  </code></pre>