title: Print even and odd lines from file
body: <p>I am trying to read from a file, then print the even elements first, followed by the odd lines. Is it best to read the lines and store them in a list for even and another for odd then print each? Or is there a more efficient way around this?</p>
  
  <p>the snippet of code below, is the method in which i am doing this sorting... As of now, it simply stores the input into a list and prints them. Is there an efficient way to print even lined words followed by odd numbered lines?</p>
  
  <pre><code>public static void test(BufferedReader r, PrintWriter w) throws IOException {
  
      ArrayList&lt;String&gt; s = new ArrayList&lt;String&gt;();
  
      String line;
      int n = 0;
      while ((line = r.readLine()) != null) {
          s.add(line);
          n++;
      }
      Iterator&lt;String&gt; i = s.iterator();
      while (i.hasNext()) {
          w.println(i.next());
      }
  }
  </code></pre>
  
  <p>thanks in advance for any help/input!</p>