Reputation: 38
How i can write this code in Java 8?
for (Iterator<RecordVo> iterator = list.iterator(); iterator.hasNext();) {
RecordVo recordVo = (RecordVo) iterator.next();
ExecutionContext singleThreadExecutionContext = new ExecutionContext();
singleThreadExecutionContext.put("customerId", recordVo.getCustomerId());
singleThreadExecutionContext.put("ThreadName", "Thread-"+recordVo.getCustomerId());
multiThreadExecutionContext.put("Partition - "+recordVo.getCustomerId(), singleThreadExecutionContext);
}
Upvotes: 0
Views: 52
Reputation: 24558
How about the following?
list.stream()
.map(RecordVo::getCustomerId)
.map(id -> {
// create singleThreadExecutionContext as before
return new SimpleImmutableEntry(id, singleThreadExecutionContext);
})
.forEach(e -> multiThreadExecutionContext.put("Partition - " + e.getKey(), e.getValue()))
I didn't compile it, but you can do that.
Upvotes: 1