Program to convert IntStream to String in Java

Java 8Object Oriented ProgrammingProgramming

Let’s first create an IntStream −

IntStream stream = "Ryan".chars();

Now, convert this IntStream to String −

String str = stream.collect(StringBuilder::new,StringBuilder::appendCodePoint,StringBuilder::append).toString();

Example

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

import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream stream = "Ryan".chars();
      String str =stream.collect
         (StringBuilder::new,StringBuilder::appendCodePoint,StringBuilder::append).toString();
      System.out.println("String (IntStream to string) = " + str);
   }
}

Output

String (IntStream to string) = Ryan
raja
Published on 25-Sep-2019 08:15:23
Advertisements