如何在Java 8流API foreach中执行此操作以继续或中断

时间:2018-08-02 12:52:52

标签: api java-8 java-stream

我有以下代码想要在每个循环中中断或继续:-

 List<Map<String, Object>> dataSource = new ArrayList<>();
Map<String, Object> rowMap2 = new LinkedHashMap<>();
  dataSource.stream().forEach(item -> {
        Map<String, Object> rowMap2 = new LinkedHashMap<>();
        if(item.get("Security").toString().equals("SECURITIES")){
            rowMap2 = item;
            for(Map.Entry<String, Object> entry : rowMap2.entrySet()){
                if(entry.getKey().equalsIgnoreCase("Security")){
                    entry.getKey().replace(entry.getKey(), mainType);
                }
            }
            dataSource2.add(rowMap2);
            // I want to continu here. 
        }
        if(entry.getKey().equals("Stock")){
            rowMap2.put(mainType, "SECURITIES");
            rowMap2.put(subType, entry.getValue());

            dataSource2.add(rowMap2);
            // I want to break from this loop here
        }
        dataSource2.add(rowMap2)
        }); 

请让我知道我该怎么做?

0 个答案:

没有答案