title: Exclude elements from ArrayList
body: <p>I'd like to iterate over an ArrayList of Strings:</p>
  
  <pre><code>List&lt;String&gt; list = new ArrayList&lt;String&gt;();
  list.add("A");
  list.add("B");
  list.add("C");
  </code></pre>
  
  <p>Instead of Iterating over all Items:</p>
  
  <pre><code>for(String a : list) {
    System.out.println(a);
  }
  </code></pre>
  
  <p>I'd like to exclude the last elements of the List. Currently I use:</p>
  
  <pre><code>for(int i = 0; i &lt; list.size()-1; i++) {
    System.out.println(list.get(i));
  }
  </code></pre>
  
  <p>But I was wondering, if there is a shorter form. For example in R you could simply generate a list without the last element:</p>
  
  <pre><code>a = c("A", "B", "C")
  a[-length(a)]
  </code></pre>