title: How can I return a specific object (index) from an arraylist in Java?
body: <p>I created a class called Student and assigned it 3 values (StudentNumber, Course, Mark); I then assigned a created student (s) to an arrayList called studentsCourses. </p>
  
  <p>This way each student takes up an index in the array. But how do I get the students back OUT of the arrayList... if that makes sense? I have them stored, but I don't know how to recall the information so that I can see it.</p>
  
  <pre><code>public static void main (String[]args){
  ArrayList&lt;Student&gt; studentsCourses= new ArrayList&lt;Student&gt;();
  String studentNumber="~";
  String course="~";
  int mark=0;
  
  Student pat;
  
  Student s=null;
  
  do{
    s=new Student();
    System.out.println("Please Enter Your Student ID (type quit to Quit):\n");
    studentNumber=keybrd.next();
    s.setStudentNumber(studentNumber);
    System.out.println("Please Enter Your Course ID:\n");
    course=keybrd.next();
    s.setCourse(course);
    System.out.println("Please Enter Your Mark:\n");
    mark=keybrd.nextInt();
    s.setMark(mark);
    s.printStates();
    studentsCourses.add(s);
  }while(!studentNumber.equals("quit"));
  
  System.out.println(studentsCourses.size());   
  System.out.println(studentsCourses);
  </code></pre>
  
  <p>so if I wanted to assign the created student (pat) the state of index 1 how would I do that?</p>
  
  <p>My one other issue (going along with this piece of code) is my sentinel. it does indeed quit when I type quit. but it finishes running through the "do" first. meaning I actually end up with a student who's number is "quit" course is whatever and mark is whatever.</p>
  
  <p>How do I force it to break the do as soon as "quit" is typed?</p>