I often need to iterate through a List starting at the second element. For example here is a column:
List<String> column = Arrays.asList("HEADER", "value1", "value2", "value3");
I need to print only values.
I see three approaches:
Using sublist:
for (String s : column.subList(1, column.size())) { System.out.println(s); }
Using ListIterator
for (ListIterator<String> iter = column.listIterator(1); iter.hasNext(); ) { System.out.println(iter.next()); }
Using index
for (int i = 1; i < column.size(); i++) { System.out.println(column.get(i)); }
What is the most preferred one considering readability, best practices and performance?
In my opinion sublist solution is more readable, but I rarely saw it in practice. Does it have any significant deficiencies comparing to index solution?