Enjoy Java 8!

Java 8: Streaming A String

  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)); }

Java 8: Reading A File Into A String

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

    public static void main(String[] args) throws IOException {
        String content = new String(Files.readAllBytes(Paths.get("duke.java")));
    }

References:
http://www.javacodegeeks.com/2014/03/java-8s-functional-fomentation.html
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s