Skip to content

Instantly share code, notes, and snippets.

@Makesh
Created March 13, 2016 17:59
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Makesh/a1defe6f1e2692aaa196 to your computer and use it in GitHub Desktop.
Save Makesh/a1defe6f1e2692aaa196 to your computer and use it in GitHub Desktop.
------------------ 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
});
@algra4
Copy link

algra4 commented Nov 22, 2019

You can use also

counter.getAndIncrement(); instead of counter.addAndGet(1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment