• List集合的过滤之lambda表达式


    下面代码 是过滤List中的对象,->后面为条件,满足条件的才会放入List中

    java 8 中lambda表达式写法
    public static void filter(List<SQLStatement> stmtList) {
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof OracleInsertStatement) && stmt.getParent() == null).collect(Collectors.toList());
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof OracleUpdateStatement) && stmt.getParent() == null).collect(Collectors.toList());
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof OracleDeleteStatement) && stmt.getParent() == null).collect(Collectors.toList());
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLSelectStatement) && stmt.getParent() == null).collect(Collectors.toList());
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLUpdateStatement) && stmt.getParent() == null).collect(Collectors.toList());
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLInsertStatement) && stmt.getParent() == null).collect(Collectors.toList());
        stmtList = stmtList.stream().filter(stmt -> !(stmt instanceof SQLDeleteStatement) && stmt.getParent() == null).collect(Collectors.toList());
    }

     java 7 以前写法

       stmtList.stream().filter(new Predicate<SQLStatement>() {
       @Override
       public boolean test(SQLStatement stmt) {
       return !(stmt instanceof OracleInsertStatement);
       }
       }).collect(Collectors.toList());

  • 相关阅读:
    勿忘心安
    设△ABC的内角A,B,C,所对的边分别为a,b,c,且acosB-bcosA=3/5c,则tan(A-B)的最大值为
    P1011 车站
    第一天
    P1134 阶乘问题
    P3152 正整数序列
    某数论
    DO YOU WANNA BUILD A SNOW MAN ?
    luogu P1579 哥德巴赫猜想(升级版)
    紫书 习题 10-25 UVa 1575 (有重复元素的全排列+暴搜)
  • 原文地址:https://www.cnblogs.com/wangchaoyu/p/8658315.html
Copyright © 2020-2023  润新知