Java 8 Stream from String

By Yashwant Chavan, Views 1197, Last updated on 06-Nov-2016

Learn how to create stream from String value in java 8.

tags java

Refer below steps.

IntStream java.lang.CharSequence.chars() method returns a stream of int (IntStream ) zero-extending the char values from this sequence.

Use forEach() method to performs an action for each element of this stream.

Java 8 Stream From String

package com.technicalkeeda.app;

public class Java8StreamFromString {
    public static void main(String[] args) {
        String str = "abcde";
        str.chars().forEach(n -> System.out.print((char) n));
    }
}

output

abcde
Yashwant

Yashwant

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan[at][gmail.com]