Java中将字符数组转换为IntStream
假设以下是我们的字符数组:
Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };将上述字符数组转换为IntStream
IntStream stream = Stream.of(arr).flatMapToInt(IntStream::of);
我们已经使用了这个flatMapToInt()方法。
下面是在Java中将字符数组转换为IntStream的示例:
示例
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };
System.out.println("The character array = ");
for (char value : arr) {
System.out.println("Value = " + value);
}
IntStream stream = Stream.of(arr).flatMapToInt(IntStream::of);
System.out.println("\nCharacter Array to IntStream = ");
stream.forEach(System.out::println);
}
}输出
The character array = Value = V Value = e Value = h Value = i Value = c Value = l Value = e Character Array to IntStream = 86 101 104 105 99 108 101
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短