Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Increment counter in lambda functions
- ------------------ Pre Java 8 ---------------------
- Map<Employee, File> fileMap = new HashMap<Employee, File>();
- int i =0;
- for (Map.Entry<Employee, File> entry : map.entrySet()) {
- i++;
- // do something with i
- }
- ------------------ Java 8 Lambda ---------------------
- AtomicInteger counter = new AtomicInteger(0);
- fileMap.forEach((k, v) -> {
- counter.addAndGet(1);
- //do something with i
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement