title: search arraylist by id-java
body: <p>The following program asks to give the number of the players and their names. I want to put the names in a arraylist and return them by their id.</p>
  
  <pre><code>private static ArrayList&lt;Player&gt;Playerlist=new ArrayList&lt;Player&gt;();
  
  public static void main(String[] args) {
  
      Scanner scanner = new Scanner(System.in);
      String s;
  
  
     {
          System.out.printf("number of players(2 -4)? ");
  
      int p = scanner.nextInt();
      scanner.nextLine();
      for(int i=0;p&gt;4 || p&lt;2;i++)
       {
  
           System.out.printf("only 2-4 players.\n");
           System.out.printf("number of players(2 -4)?");
           p = scanner.nextInt();
           scanner.nextLine();
  
       }
     Player pl=new Player();
     int m=1;
      for(int k=1;k&lt;=p;k++)
       {
  
  
           System.out.printf("give the name of the player %d: ",k);
           s= scanner.nextLine();
           pl.setName(s,m);
           System.out.printf(pl.getName());
           Playerlist.add(pl);
         m++;
        }
    public class Player {
  
    private String name;
    private int id;
  
    public Player () {
     }
  
    Player(String val,int k) {
      this.name = val;
      this.id=k;}
    /**
     * getName
    *
    */
  public String getName () {
      return name;
  }
  
  /**
   * setName
  
   */
  public void setName (String val,int k) {
      this.name = val;
      this.id=k;
  }
  public void displayStudentDetails(){
      System.out.println("ID is "+id);
      System.out.println("Name is "+name)};
  </code></pre>
  
  <p>i dont know how to do the search by id...i have tried many things but they didnt work....</p>