Adam Bien's Weblog

Java 8: Dumping Content Of a Map


Map<String, String> map = new HashMap<>();
	map.put("java", "42");
	map.forEach((key, value)
			-> System.out.printf("Key: %s Value: %s", key, value)
	);
}

Output: Key: java Value: 42


NEW workshop: Microservices with Java EE 7 and Java 8, January 26th, 2015, Airport Munich

A book about rethinking Java EE Patterns

Comments:

Now java is just lacking some nice snytax to create and fill a map.

Like in php where you can do:

myMap = array (
'key1' => 'Value1',
'key2' => 'Value2'
);

Posted by Christian Schneider on February 28, 2014 at 10:13 AM CET #

Bad example is it?

Map<String,Object> myMap = new HashMap<>();
myMap.put("key1", "Value1");
myMap.put("key2", "Value2");

1 line less than the example (yeah, nit picking ...). There are things PHP is nicer to work with than java and things where java just shines above PHP.

Posted by Matthias on March 01, 2014 at 04:27 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License