avatar
docsconsole
0

Codes

5

Answers

Code compilers

Top answers

0
foreach map java
February-06-2023
        // 2 Iterating over entrySet of map
        Map<String, Integer> cityPINsMap = new HashMap<>();
        cityPINsMap.put("NewDelhi", 110001);
        cityPINsMap.put("NewYork", 10001);
        cityPINsMap.put("Sydney", 2000);
        for (Map.Entry<String, Integer> entry : cityPINsMap.entrySet()) {
            System.out.println("City = " + entry.getKey() + ", PIN = " + entry.getValue());
        }
0
java 8 map foreach
February-06-2023
        //4.  Iterating through forEach
        Map<Integer, String> countriesMap = new HashMap<>();
        countriesMap.put(1, "India");
        countriesMap.put(2, "USA");
        countriesMap.put(3, "Australia");
        countriesMap.forEach((k, v) -> System.out.println("No = " + k + ", Country = " + v));
0
iterate map in java 8 using stream
February-06-2023
        //5.  Iterating through forEach java 8
        Map<Integer, String> contentsMap = new HashMap<>();
        contentsMap.put(1, "India");
        contentsMap.put(2, "USA");
        contentsMap.put(3, "Australia");
        contentsMap.entrySet().stream().forEach(e ->
                System.out.println("No : " + e.getKey() + " Content : " + e.getValue())
        );
0
for each map java
February-06-2023
        // 2 Iterating over entrySet of map
        Map<String, Integer> cityPINsMap = new HashMap<>();
        cityPINsMap.put("NewDelhi", 110001);
        cityPINsMap.put("NewYork", 10001);
        cityPINsMap.put("Sydney", 2000);
        for (Map.Entry<String, Integer> entry : cityPINsMap.entrySet()) {
            System.out.println("City = " + entry.getKey() + ", PIN = " + entry.getValue());
        }
0
java 8 map foreach
February-06-2023
        //4.  Iterating Map through forEach
        Map<Integer, String> countriesMap = new HashMap<>();
        countriesMap.put(1, "India");
        countriesMap.put(2, "USA");
        countriesMap.put(3, "Australia");
        countriesMap.forEach((k, v) -> System.out.println("No = " + k + ", Country = " + v));