title: Stack in java not working properly?
body: <p>I am trying to store data into the stack.Correct me if I am wrong, stack is a Last in, first out type. So, was expecting that the output of my program will be kinda reverse. But sad to say the output is different. I am not sure what part of the codes is wrong. </p>
  
  <p>Please help :|</p>
  
  <p>CODE:</p>
  
  <p>`</p>
  
  <p>public class CorruptQueue
  {</p>
  
  <pre><code>public static void LineUp(){
  
      BufferedReader br = null;
  
  try {
  
      String line;
      Stack nameStack = new Stack();
      Stack statusStack = new Stack();
      Stack stack = new Stack();
  
      br = new BufferedReader(new FileReader("C:/Users/user/Desktop/School Files/Project/CorruptOffice/input.txt"));
  
      while ((line = br.readLine()) != null) {
  
  
         StringTokenizer stringTokenizer = new StringTokenizer(line, " ");
  
         while (stringTokenizer.hasMoreElements()) {
  
  
          String lineup = stringTokenizer.nextElement().toString();
          String name = stringTokenizer.nextElement().toString();
          String status = stringTokenizer.nextElement().toString();
  
  
  
              nameStack.push(name);
              statusStack.push(status);
              System.out.println("Now serving "+ nameStack.pop() + " a " + statusStack.pop());
  
  
  
          /*StringBuilder sb = new StringBuilder();
          sb.append("" + lineup);
          sb.append(" " + name);
          sb.append("" + status);
          sb.append("\n\n");
  
          System.out.println(sb.toString());*/
         }
  
      }
  
      System.out.println("Done");
  
  } catch (IOException e) {
      e.printStackTrace();
  } finally {
      try {
          if (br != null)
              br.close();
  
      } catch (IOException ex) {
          ex.printStackTrace();
      }
  }
  
      }
  
  
  
  public static void main(String[] args) 
  {
       LineUp();
  </code></pre>
  
  <p>}
  }`</p>
  
  <p>INPUT:</p>
  
  <p>lineup John regular</p>
  
  <p>lineup Bob regular</p>
  
  <p>lineup Tom regular</p>
  
  <p>lineup Sarah VIP</p>
  
  <p>lineup Marie VIP</p>
  
  <p>lineup Joan VIP</p>
  
  <p>lineup Bea VIP</p>
  
  <p>lineup Hank regular</p>
  
  <p>lineup Art regular</p>
  
  <p>lineup Daisy VIP</p>
  
  <p>lineup Marius regular</p>
  
  <p>lineup Dane VIP</p>
  
  <p>OUTPUT:</p>
  
  <p>Now serving John a regular</p>
  
  <p>Now serving Bob a regular</p>
  
  <p>Now serving Tom a regular</p>
  
  <p>Now serving Sarah a VIP</p>
  
  <p>Now serving Marie a VIP</p>
  
  <p>Now serving Joan a VIP</p>
  
  <p>Now serving Bea a VIP</p>
  
  <p>Now serving Hank a regular</p>
  
  <p>Now serving Art a regular</p>
  
  <p>Now serving Daisy a VIP</p>
  
  <p>Now serving Marius a regular</p>
  
  <p>Now serving Dane a VIP</p>
  
  <p>Done</p>