Java for each

Java for each Maps:

Map<String, String> iAmSimpleMap = new LinkedHashMap<>();

iAmSimpleMap.entrySet().forEach(entry -> 
           System.out.println("Key" + entry.getKey() + " and Value " +  entry.getValue()));

Java for each Maps:

for (Map.Entry<String, Set<String>> entry : IamAMapwithThesameFormat.entrySet()) {

        String iAmAKey = entry.getKey();
        Set<String> iAmValue = entry.getValue();

        int iAmInteger = someFunction(iAmValue );

        System.out.printf("%s: I am some random Text %d\n", iAmAKey, iAmValue);

        }

„for each“ Maps:

String myNewString = IamAmap
           .entrySet()
           .stream()
           .map(mapEntry -> String.format("%s => %d", mapEntry.getKey(), mapEntry.getValue()))
           .collect(Collectors.joining(", "));

System.out.println(myNewString + ":");


// entrySet() = give the records one after the other, iterate on them
// stream() = put every entity (pair) on a stream -> conduct a function/method on every pair
// .map = changes something into something else
// .collect(Collectors.joining(", ")) = collect the set of texts with ", " as delimiter

error: Content is protected !!