Skip to content

Instantly share code, notes, and snippets.

@marchev
Created August 31, 2017 20:02
Show Gist options
  • Save marchev/14d02ec5f5b9b810737c1bc12e096f05 to your computer and use it in GitHub Desktop.
Save marchev/14d02ec5f5b9b810737c1bc12e096f05 to your computer and use it in GitHub Desktop.
Iterators and shit
jshell> listOfFoos.stream().forEach(foo -> foo.setFoo(stringValues.iterator().next()));
jshell> listOfFoos.stream().forEach(x -> System.out.println(x.getFoo()));
one
one
one
-----------------------------------------------------------------------------------------
jshell> Iterator<String> strValsIterator = stringValues.iterator();
strValsIterator ==> java.util.Arrays$ArrayItr@6c3708b3
jshell> listOfFoos.stream().forEach(foo -> foo.setFoo(strValsIterator.next()));
jshell> listOfFoos.stream().forEach(x -> System.out.println(x.getFoo()));
one
two
three
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment