1.Stream在Java8中被定义为泛型接口
2.Stream接口代表数据流
3.Stream不是数据结构,不之间存储数据
4.Stream通过管道操作数据
5.创建Stream接口实现类对象
1.DoubleStream接口表示元素类型是double的数据源
2.DoubleStream接口的常用方法:
max().getAsDouble()
获取流中数据集的最大值
min().getAsDouble()
获取流中数据集的最小值
average() 获取流中数据的平均值
public class Test03 {
public static void main(String[] args) {
Listpeople = createPeople();
Streamstream = people.stream();
stream.filter(p->p.getGender()==Person.Sex.FEMAIL)
.forEach(
p->System.out.println(p.toString())
);
Listpeople1 = createPeople();
double avgHeight = people1.stream()
.filter(p->p.getName().indexOf("飞")>=0)
.mapToDouble(p->p.getHeight())
.average()
.getAsDouble();
System.out.println("带有飞子的人的平均身高:"+avgHeight);
}
static ListcreatePeople(){
Listpeople = new ArrayList();
Person p = new Person("张飞",Person.Sex.MAIL,33,1.9);
people.add(p);
p = new Person("王飞",Person.Sex.FEMAIL,23,1.7);
people.add(p);
return people;
}
}
LocalDate类的常用方法:
1.LocalDate.now():获取系统当前日期。
2.LocalDate.of(int year,int month,int dayOfMonth)
按指定日期创建LocalDate对象。
3.getYear():返回日期中的年份。
4.getMonth():返回日期中的月份。
5.getDayOfMonth():返回月份中的日。
LocalTime类的常用方法:
1.LocalTime.now():获取系统当前时间。
2.LocalTime.of(int hour,int minute,int second)
按指定时间创建LocalTime对象。
3.getHour():返回小时。
4.getMinute():返回分钟。
5.getSecond():返回秒。
LocalDateTime类的常用方法:
1.LocalDateTime.now():获取系统当前时间。
2.LocalDateTime.of(int year,int month,int dayOfMonth
,int hour,int minute,int second)
按指定日期和时间创建LocalDateTime对象
3.getYear():返回日期中的年份。
4.getMonth():返回日期中的月份。
5.getDayOfMonth():返回月份中的日。
6.getHour():返回小时。
7.getMinute():返回分钟。
8.getSecond():返回秒。
DateTimeFormatter类用于将字符串解析为日期
DateTimeFormatter formatter = DateTimeFormatter.ofPattern
("yyyy-MM-dd HH:mm:ss");
LocalDateTime date = LocalDateTime.parse("2014-04-01 13
-:24:01",formatter);
ZonedDateTime处理日期和时间与对应的时区
1.ZonedDateTime.now()获取系统当前日期和事件
2.String format(DateTimeFormatter formatter)
按指定模板将日期对象格式化为一个字符串