title: How to create a search method for an array
body: <p>My code is as follows: </p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class readStudents extends Object
  { 
      private String SName = "";
      private String DoB = "";
      private String Gender = "";
      private String Address = "";
      Student [] students = new Student[20];
  
  
      public void fillStudentArray()
      {
          // properties
  
          int size; // total number of Students in collection
  
          File file = new File("StudentDetails.txt");
  
      try
      {
          Scanner in  = new Scanner(file);
  
  
          while(in.hasNextLine())
          {
              String SName = in.next();
              String DoB = in.next();
              String Gender = in.next();
              String Address = in.next();
  
          }
  
      }
  
      catch (FileNotFoundException e)
      {
          e.printStackTrace();
      }
  
      }   
  
      public String getName()
      {
          return this.SName;
      } 
  
      public void printname()
      {
          System.out.println("hello");
      }
      public Student search(String name)
      {
          System.out.print("Enter the name you wish to search: ");
  
          for (int i = 0; i &lt; this.students.length; i++)
          {
              Student s = this.students[i];
              if (s.getName().equalsIgnoreCase(name))
              {
                  return s;
              }
          }
          return null; 
      }
  }   //end class students
  </code></pre>
  
  <p>However I am trying to create a well refined program that I can call on these methods from another main file with as minimal code as possible in that file.  </p>
  
  <p>The search method at the bottom is tripping me up as I am assuming I need to put something to do with the array in my <code>getName()</code> method but I can't figure it out.  </p>
  
  <p>Since I am doing this as a class for another main method, with the placement of my array initialization and declaration it allows the other methods to access it but it leaves me with no way to create this array from the main method unless I am missing something?</p>
  
  <p>This is the error <code>jCreator</code> is throwing: </p>
  
  <pre><code>F:\University\Ass2\readStudents.java:62: error: cannot find symbol
              if (s.getName().equalsIgnoreCase(name))
  
                   ^
  symbol:   method getName()
  location: variable s of type Student
  </code></pre>