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: HTML 5 and JavaScript Essentials, Three days in April 2017: from Java EE 7 Architectures over Microservices to Performance, Troubleshooting and Monitoring
On demand workshops: Java EE 7: Bootstrap, Effective, Testing and Microservices available for streaming.


A book about rethinking Java EE Patterns


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
Online Workshops
...the last 150 posts
...the last 10 comments