title: 'Using a for loop to compare if each element of an ArrayList equals a user response
body: <p>I have already figured out how to do it using a different method but apparently I must use a for loop, I feel like i'm using the wrong syntax or something but I have googled and searched for close to an hour now so I have no idea how to fix this seemingly easy problem.</p>
  
  <p>Here is what I think is the relevant part of the code:</p>
  
  <pre><code>public static void deleteEntry()
      {
          response =  JOptionPane.showInputDialog("Please enter a bird name to REMOVE it from the list");
  
          for(int i=0;i&lt;birdList.size();i++)
          {
              if(birdList(i).equals(response)) **//this line is giving me an error. birdList has a red line under it in eclipse.**
              {
                  birdList.remove(response);
                  JOptionPane.showMessageDialog(null, response + " removed!");
              }
              else if(i == birdList.size())
              {
                  JOptionPane.showMessageDialog(null, "The bird you tried to remove was not on the list");
              }
          }
  
          /* How I was originally going to do it before I re-read the requirements.
          /*if(birdList.contains(response))
          {
              birdList.remove(response);
              JOptionPane.showMessageDialog(null, response + " removed!");
          }
          else
          {
          JOptionPane.showMessageDialog(null, "The bird you tried to remove was not on the list");
          }*/
  </code></pre>
  
  <p>Here is all the code:
      import java.util.ArrayList;
      import javax.swing.JOptionPane;</p>
  
  <pre><code>public class BirdArrayList {
  
      static ArrayList&lt;String&gt; birdList = new ArrayList&lt;String&gt;(5); 
      static String response;
  
      public static void main(String[]args)
      {
  
          birdList.add("Crow");  //adding fice initial birds to the birdList ArrayList
          birdList.add("Magpie");
          birdList.add("Dove");
          birdList.add("Finch");
          birdList.add("Kookaburra");
  
  
          while (response != "5")
          {
              response =  JOptionPane.showInputDialog("Please enter the number for what you wish to do \n"
                      + " 1 \t ADD a bird to the list \n"
                      + " 2 \t REMOVE a bird from the list \n"
                      + " 3 \t SEARCH for a bird in the list \n"
                      + " 4 \t DISPLAY the list of birds \n"
                      + " 5 \t QUIT the program"); // Main screen of the program, formatted nicely
  
              if(response.equals("1")) // Add a bird
              {
                  addEntry();
              }
  
              if(response.equals("2"))//Remove a bird from the list
              {
                  deleteEntry();
              }
  
              if(response.equals("3"))//Search for a bird
              {
                  //searchEntry();
              }
  
  
              if(response.equals("4"))  // Displays the array
              {
                  displayArray();
              }
              if(response.equals("5")) // Quit the program
              {
                  System.exit(0);
              }
          }
  
      }
  
      public static void addEntry()
      {
          response =  JOptionPane.showInputDialog("Please enter a bird name to ADD it to the list"); 
          birdList.add(response); // adds the response to the birdList in the next Array position
           JOptionPane.showMessageDialog(null, response + " added!"); // Shows bird name added
           displayArray();
      }
  
      public static void deleteEntry()
      {
          response =  JOptionPane.showInputDialog("Please enter a bird name to REMOVE it from the list");
  
          for(int i=0;i&lt;birdList.size();i++)
          {
              if(birdList(i).equals(response))
              {
                  birdList.remove(response);
                  JOptionPane.showMessageDialog(null, response + " removed!");
              }
              else if(i == birdList.size())
              {
                  JOptionPane.showMessageDialog(null, "The bird you tried to remove was not on the list");
              }
          }
  
          /* How I was originally going to do it before I re-read the requirements.
          /*if(birdList.contains(response))
          {
              birdList.remove(response);
              JOptionPane.showMessageDialog(null, response + " removed!");
          }
          else
          {
          JOptionPane.showMessageDialog(null, "The bird you tried to remove was not on the list");
          }*/
      }
      public static void displayArray()
      {
          String displayList = "";
          int tempCounter = 0;
          for(int i=0;i&lt;birdList.size();i++) //Display the ArrayList 
          {
              String tempBird = birdList.get(i); //Makes tempBird more workable in the displayList formula 2 lines down
              tempCounter++; // shows a nuber before the bird in the list
              displayList += tempCounter + ".   " + tempBird + "\n";   //formatting nicely    
          }
              JOptionPane.showMessageDialog(null, displayList); //Displays the list
  
      }
  }
  </code></pre>