假设以下是我们的字符串-
String str = "My String";
现在,将以上内容转换为IntStream-
IntStream stream = str.chars();
以下是在Java中将String转换为IntStream的程序-
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); } }
输出结果
String: My String IntStream... 77 121 32 83 116 114 105 110 103