Are there any benefits in using the new Stream API for simple iterations?
Without Stream API:
for (Map.Entry<String, String> entry : map.entrySet()) {
doSomething(entry);
}
Using Stream API:
map.entrySet().stream().forEach((entry) -> {
doSomething(entry);
});
Length and readability of code are about the same. Are there any important differences (e.g. in performance)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…