JAVA 8: Streaming a String

Streaming a String using Java 8.

public static void main(String[] args) {
        "hey duke".chars().forEach(c -> System.out.println((char)c));
    }

The parallel version does not preserve the order (and comes with additional overhead):

public static void main(String[] args) {
        "hey duke".chars().parallel().forEach(c -> System.out.println((char) c));
    }

Enjoy Java 8!

 

Published by

Claudio Cardozo

Ubuntu Kernel Team Membership, Certified SCRUM Master, System Architect, Open Source enthusiastic, Java and JavaFX passioned, OpenCRX Team, Theologist, minimalist lifestyle, eitaa!

Leave a Reply