当前位置:网站首页>Introduction to intstream API

Introduction to intstream API

2022-06-25 04:24:00 It's hard not to write code all day

1 establish int Type array

import java.util.stream.IntStream;


IntStream range = IntStream.range(0, 10);

2 boxed()

boxed It's always been mapToObject(Integer::vaueOf)

The elements in the collection are of reference type , Basic data types need to be boxed , To become list

 IntStream.range(0,10).boxed().collect(Collectors.toList());

3 mapToDouble()

These three methods return three specified types of stream Other use methods and functions besides map similar , amount to map A special case of the method .

list.stream().mapToDouble(User::getAge).sum()// and 
list.stream().mapToDouble(User::getAge).max()// Maximum 
list.stream().mapToDouble(User::getAge).min()// Minimum 
list.stream().mapToDouble(User::getAge).average()// Average 
原网站

版权声明
本文为[It's hard not to write code all day]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206250210375310.html