zoukankan      html  css  js  c++  java
  • jdk8 list是否包含某值的一些应用

    memberList.forEach(aa -> {String householderRelation = aa.getHouseholderRelation();});

    List<Map<String, String>> list = new ArrayList<>();
    HashMap<String, String> map = new HashMap<>();
    map.put("1","张三");
    HashMap<String, String> map1 = new HashMap<>();
    map1.put("1","李四");
    HashMap<String, String> map2 = new HashMap<>();
    map2.put("1","王五");
    HashMap<String, String> map3 = new HashMap<>();
    map3.put("1","赵六");
    list.add(map);
    list.add(map1);
    list.add(map2);
    list.add(map3);

    boolean present = list.stream().filter(m -> "张三".equals(m.get("1").toString())).findAny().isPresent();//是否有户主
    System.out.println(present);

    boolean b1 = list.stream().anyMatch(task -> task.get("1").toString().equals("张三"));
    System.out.println(b1);


    List<Order> list = new ArrayList<User>();
    Order o1 = new Order("1","MCS-2019-1123");
    list.add(o1 );
    Order o2= new Order("2","MCS-2019-1124");
    list.add(o2);
    Order o3= new Order("3","MCS-2019-1125");
    list.add(o3);
    List<String> orderNoList=list.stream().map(Order::getOrderNo).collect(Collectors.toList());
    System.out.println("输出单号集合:"+orderNoList);
    List<String> idList=list.stream().map(Order::getId()).collect(Collectors.toList());
    System.out.println(idList)

  • 相关阅读:
    Servlet
    反射
    Python之装饰器
    app——升级测试点
    Python之基本运算符
    HTTP常见的几种认证机制
    Shell文件包含
    Shell输入/输出重定向
    Shell函数
    Shell循环语句
  • 原文地址:https://www.cnblogs.com/xyyou/p/14558180.html
Copyright © 2011-2022 走看看