JDK 1.8新特性stream()
1:Map.forEach 遍历
// 创建一个Map
Map<String, Object> infoMap = new HashMap<>();
infoMap.put("name", "Zebe");
infoMap.put("site", "www.zebe.me");
infoMap.put("email", "zebe@vip.qq.com");
// 传统的Map迭代方式
for (Map.Entry<String, Object> entry : infoMap.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
// JDK8的迭代方式
// key/value:变量名
infoMap.forEach((key, value) -> {
System.out.println(key + ":" + value);
});
2:stream 比较
//学生类
public class Student{
//编号
private String id;
//姓名
private String name;
//年龄
private String age;
}
public class Test{
public static void main(String args[]) {
//5个学生对象
Student studentOne = new Student("1","张三","99");
Student studentTwo = new Student(&