DEV Community 👩‍💻👨‍💻

Discussion on: For Loop in different programming languages

everton profile image
Everton Agner • Edited on

Let's be fair with Java. The language has seen quite a few enhancements since Java 8 release, 3 years ago, and very recently on Java 9, both on API and syntax. Now using the new stuff...

Loop a string:

String str = "hello";
str.chars() // Produces a stream of integers... yeah, that's odd
    .mapToObj(i -> (char) i) // Now we have a stream of chars

Loop a collection:

List<String> list = List.of("a", "b");