gpt4 book ai didi

java - 如何使用 lambdaj 或其他工具过滤表

转载 作者:太空宇宙 更新时间:2023-11-04 08:27:24 28 4
gpt4 key购买 nike

如何使用 lambdaj 过滤表格?

给出下表:

id  name   age  male  salary1   tom    22    y      3k2   nancy  24    n      3.5k3   jack   22    y      2k4   jmme   29    y      4k

If I applied the filter:

age >= 22 && salary > 3k

然后我会得到:

2   nancy  24    n      3.5k4   jmme   29    y      4k

As you know, I cannot create a domain class for it, which prevents me from using the following syntax:

filter(having(on(Person.class).getAge(),greaterThan(22)), myManList);

最佳答案

   /**         *          *  序号   年份 地区      GDP         *  1       2011    北京      1233         *  2       2010    天津      2412         *  3       2012    上海      1939         *  4       2009    深圳      1389         *  5       2013    重庆      1492         * */         Table aTable = HashBasedTable.create();           aTable.put("1", "id", "1");         aTable.put("1", "年份", "2011");         aTable.put("1", "地区", "北京");         aTable.put("1", "GDP", "1233");         aTable.put("2", "id", "2");         aTable.put("2", "年份", "2010");         aTable.put("2", "地区", "天津");         aTable.put("2", "GDP", "2412");         aTable.put("3", "id", "3");         aTable.put("3", "年份", "2012");         aTable.put("3", "地区", "上海");         aTable.put("3", "GDP", "1939");         aTable.put("4", "id", "4");         aTable.put("4", "年份", "2009");         aTable.put("4", "地区", "深圳");         aTable.put("4", "GDP", "1389");         aTable.put("5", "id", "5");         aTable.put("5", "年份", "2013");         aTable.put("5", "地区", "重庆");         aTable.put("5", "GDP", "1492");         List>  li = filter(                    having(on(Map.class).get("年份"),isIn(Arrays.asList("2009","2011")))                    .and(having(on(Map.class).get("地区"),isIn(Arrays.asList("深圳"))))                            ,aTable.rowMap().values());         System.out.println(li);

关于java - 如何使用 lambdaj 或其他工具过滤表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8236568/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com