InterviewSolution
| 1. |
What Is Foreach Statement Added In Java 8? |
|
Answer» Java 8 has added a functional style lopping to the COLLECTIONS. Real ADVANTAGE of this loop is when it is used on a stream with the chain of functional methods. If you have a Map<STRING, String> then it can be looped using ForEach statement like this - Set<Map.Entry<String, String>> valueSet = cityMap.entrySet(); valueSet.forEach((a)->System.out.println("Key is " + a.getKey() + " Value is " + a.getValue())); Java 8 has added a functional style lopping to the Collections. Real advantage of this loop is when it is used on a stream with the chain of functional methods. If you have a Map<String, String> then it can be looped using ForEach statement like this - Set<Map.Entry<String, String>> valueSet = cityMap.entrySet(); valueSet.forEach((a)->System.out.println("Key is " + a.getKey() + " Value is " + a.getValue())); |
|