table番石榴消除columKey

table guava elimination columKey

我有一个 table 和一个 hashmap,我想删除(消除)番石榴 table 中不在键 hashmap

中的列

例子

table guava

{5667={20=10, 222=7, 547=10, 1590=10, 3802=10, 4383=3, 5680=10, 7987=9, 
      9181=10, 9325=2},
7021={20=8, 222=8, 547=9, 1590=10, 3802=3, 4383=1, 5680=9, 7987=9,
      9181=9, 9325=2}}

my HashMap hm
{20=0, 222=0, 3802=0, 4383=0, 7987=0, 9181=0, 9325=0}

结果

new Table table (same table)

{5667={20=10, 222=7, 3802=10, 4383=3,7987=9,9181=10, 9325=2},
7021={20=8, 222=8, 3802=3, 4383=1,7987=9, 9181=9, 9325=2}}

我的代码

   public class columnElimination {

   public static Table< Integer, Integer, Integer> doc(Table< Integer, 
   Integer, Integer> table, HashMap< Integer, Integer> hm) throws 
    ClassNotFoundException {

    table.columnMap().keySet().removeIf(key -> !hm.containsKey(key));
    System.out.println("new table");
    System.out.println(table);
    return (table);
}
}

但这没有用

应该 有效,但你没有解释你得到了什么例外。与此同时,无论如何我会更简单地写成 table.columnKeySet().retainAll(hm.keySet())