相关疑难解决方法(0)

通过满足特定条件的值删除元素

我想从这些数据结构中按值删除满足某些条件的元素

<Data Structures>

 - RowSortedTable<String, String, Double> a;     (Guava Table)
 - HashMap<String, Double> b;
Run Code Online (Sandbox Code Playgroud)

从上一个问题中,我找到了使用的简洁答案Collections.Singleton,但是似乎需要精确匹配。

hmap.values().removeAll(Collections.singleton("Two"));
Run Code Online (Sandbox Code Playgroud)

在这里,我想从表或映射中删除其值小于特定阈值的元素。您编写代码的方式是什么?


我只检查了两个答案,这些是关于map的答案,表情况如何?我的解决方案如下。

for (Iterator<String> it1 = proptypeconf.columnKeySet().iterator(); it1.hasNext();) {
        String type = it1.next();
        System.out.println(type);
        for (Iterator<Map.Entry<String, Double>> it2 = proptypeconf.column(type).entrySet().iterator(); it2.hasNext();){
            Map.Entry<String, Double> e = it2.next();
            if (e.getValue() < conflist.get(index-1)) {
                it2.remove();
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

java dictionary data-structures

4
推荐指数
1
解决办法
840
查看次数

标签 统计

data-structures ×1

dictionary ×1

java ×1