首先创建一个IntStream-
IntStream stream = "Ryan".chars();
现在,将此IntStream转换为String-
String str = stream.collect(StringBuilder::new,StringBuilder::appendCodePoint,StringBuilder::append).toString();
以下是在Java中将IntStream转换为String的程序-
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); } }
输出结果
String (IntStream to string) = Ryan