Performing specific operation on first element of list using Java8 streaming
I want to perform certain operation on first element of my list and different operation for all remaining elements. Here is my code snippet: List<String> tokens = getDummyList(); if (!tokens.isEmpty()) { System.out.println("this is first token:" + tokens.get(0)); } tokens.stream().skip(1).forEach(token -> { System.out.println(token); }); Is there any more cleaner way to achieve this preferably using java 8 streaming API. Holger One way to express the intention is Spliterator<String> sp = getDummyList().spliterator(); if(sp.tryAdvance(token -> System.out.println("this is first token: "+token)))