Program to convert IntStream to String in Java


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

Updated on: 25-Sep-2019

72 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements