Program to convert String to IntStream in Java


Let’s say the following is our string −

String str = "My String";

Now, convert the above to IntStream −

IntStream stream = str.chars();

Example

Following is the program to convert String to IntStream in Java −

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      String str = "My String";
      System.out.println("String: " + str);
      IntStream stream = str.chars();
      System.out.println("IntStream...");
      stream.forEach(System.out::println);
   }
}

Output

String: My String
IntStream...
77
121
32
83
116
114
105
110
103

Updated on: 25-Sep-2019

78 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements