Skip to content

Instantly share code, notes, and snippets.

@filevich
Last active September 3, 2020 11:51
Show Gist options
  • Save filevich/469046de137c7f23c8d951e00057832d to your computer and use it in GitHub Desktop.
Save filevich/469046de137c7f23c8d951e00057832d to your computer and use it in GitHub Desktop.
// for :
// by keys
for (String i : capitalCities.keySet()) {
System.out.println("key: " + i + " value: " + capitalCities.get(i));
}
// by values
for (String i : capitalCities.values()) {
System.out.println(i);
}
// by <entry,value>
for (Map.Entry<Integer, String> entry : datos.entrySet()) {
System.out.println("clave=" + entry.getKey() + ", valor=" + entry.getValue());
}
// foreach (cannot `returns <Type>`, only `return;` as a `break;`)
names.forEach(name -> {
System.out.println(name);
});
datos.forEach((k,v) -> System.out.println("Key: " + k + ": Value: " + v));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment