小编use*_*512的帖子

Java 8 Map KeySet Stream 在收集器中无法按预期使用

我一直在尝试学习 Java 8 的新功能接口特性,但在重构我之前编写的代码时遇到了一些困难。

作为测试用例的一部分,我想在 Map 结构中存储读取名称列表,以便检查这些读取是否已在后续代码部分“修复”。我正在从现有的 Map> 数据结构进行转换。我之所以要扁平化这个数据结构,是因为在后续的分析中不需要原始 Map 的外部“String”键(我用它来分离来自不同来源的数据,然后再将它们合并到中间数据中)。这是我原来的程序逻辑:

public class MyClass {
  private Map<String, Map<String, Short>> anchorLookup;
  ...
  public void CheckMissingAnchors(...){
    Map<String, Boolean> anchorfound = new HashMap<>();

    // My old logic used the foreach syntax to populate the "anchorfound" map
    for(String rg : anchorLookup.keySet()){
      for(String clone : anchorLookup.get(rg).keySet()){
        anchorfound.put(clone, false);
      }
    }
    ...
    // Does work to identify the read name in the file. If found, the boolean in the map
    // is set to "true." Afterwards, …
Run Code Online (Sandbox Code Playgroud)

java collections set java-8 java-stream

3
推荐指数
2
解决办法
5937
查看次数

标签 统计

collections ×1

java ×1

java-8 ×1

java-stream ×1

set ×1