1
我想將我的Hashmap for循環轉換爲Java8流。這是我的代碼。Java streaming Hashmap
int amount = 100;
Map<String, Account> map = accountMap;
for (Map.Entry<String, Account> entry : map.entrySet()) {
String id = entry.getValue().getAccount_id();
updateAccount(amount, id);
}
它會是這樣,但想不出確切的語法:
accountMap.entrySet().parallelStream()
.collect(Collectors.toMap(
e -> e.getKey(),
e -> e.getValue()
//Where can I call external method?
));
'map.values()的forEach(V? - > changeAmount(金額,v.getAccount_id())'但是我會保持你的循環只是,遍歷所有的值,而不是條目集。因爲你不想要密鑰 – Tunaki
@Tunaki多數民衆贊成在每一個而不是並行流? – Spring
@Tunaki我看到,但我想使用並列從多線程利用 – Spring