banner
指数爆炸

指数爆炸

我做了对饭 !
github
bilibili

If a Stream does not have a terminal operation, it will ...

If a Stream does not have a terminal operation, the intermediate operations of this stream will not be executed


This is the code I wrote today, I found that there was no data in the list at the end, so I debugged it. During debugging, I found that the entire peek() operation was not executed and was skipped directly.

List<JSONObject> list = new ArrayList<>();
sbdqas.queryAll(qs).stream()
        .peek(AbstractStandingBookData -> {
            Map<String, String> contentMap = AbstractStandingBookData.toContentMap();
            contentMap.put("totalReceivables", AmountUtil.convertAmountSmallFormat(contentMap.get("totalReceivables")));
            contentMap.put("totalPayable", AmountUtil.convertAmountSmallFormat(contentMap.get("totalPayable")));
            list.add(new JSONObject(contentMap));
        });

Later, I refactored the code, directly used the map() operation to return JSONObject, and then used the terminal operation toList() to finish perfectly!!!

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.