Program to convert String to IntStream in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 25-Sep-2019 08:20:40
Advertisements