Java 9 | Streams | For loop with index – iterate() | While loop – takeWhile(), dropWhile()

In Java 9, there are few useful methods introduced to java.util.stream.Stream.

  • Stream.iterate – For loop with index. Equivalent for  for (int i = 0; i < sortedNames.length; i++) {...}
  • Stream.takeWhile – While loop takes value while condition is met
  • Stream.dropWhile – While loop drops value while condition is met

Output

 

Leave a Reply

Your email address will not be published. Required fields are marked *