I’m sure there’s some nice library that does this sort of thing already for you… But to just stick with the approach you’re already going with, Map#entrySet
gives you a combined Object
with the key
and the value
. So something like:
for (Map.Entry<String, Object> entry : map.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue().toString()); }
will do what you’re after.
If you’re using java 8, there’s also the new streaming approach.
map.forEach((key, value) -> System.out.println(key + ":" + value));
Related Posts:
- ConcurrentHashMap and Hashtable in Java
- What is a hash function in java?
- What is a hash function in java?
- Java associative-array
- What are the differences between a HashMap and a Hashtable in Java?
- Exception in thread “main” java.lang.StackOverflowError
- Difference between HashSet and HashMap?
- Exception in thread “main” java.lang.StackOverflowError
- Iterate through a HashMap [duplicate]
- C# Java HashMap equivalent
- C# Java HashMap equivalent
- Iterate through a HashMap [duplicate]
- What is the significance of load factor in HashMap?
- How to update a value, given a key in a hashmap?
- Collision resolution in Java HashMap
- Hashtable, HashMap, HashSet , hash table concept in Java collection framework
- Difference between HashMap and Map in Java..?
- Java Hashmap: How to get key from value?
- Sorting HashMap by values
- How to sort Map values by key in Java?
- HashMap get/put complexity
- What is the difference between the HashMap and Map objects in Java?
- “Cannot create generic array of ..” – how to create an Array of Map
? - Map of maps – how to keep the inner maps as maps?
- toring and Retrieving ArrayList values from hashmap
- How to solve could not create the virtual machine error of Java Virtual Machine Launcher?
- Convert String to double in Java
- What is float in Java?
- What does value & 0xff do in Java?
- How do I make a delay in Java?
- Initialization of an ArrayList in one line
- What does the “+=” operator do in Java?
- Is there a Heap in java?
- What’s the difference between map() and flatMap() methods in Java 8?
- Why do we need copy constructor and when should we use copy constructor in java
- What are the -Xms and -Xmx parameters when starting JVM?
- How to match “any character” in regular expression?
- Exception in thread “main” java.lang.Error: Unresolved compilation problems
- String variable interpolation Java [duplicate]
- Non-static variable cannot be referenced from a static context
- JAVA invalid maximum heap size. The specified size exceeds the maximum representable size
- JDK9: An illegal reflective access operation has occurred. org.python.core.PySystemState
- How to encrypt String in Java
- Usage of @see in JavaDoc?
- Hadoop “Unable to load native-hadoop library for your platform” warning
- Unreported exception java.lang.Exception; must be caught or declared to be thrown
- How to clear the console?
- How to capitalize the first letter of a String in Java?
- Scanner vs. BufferedReader
- Control an Arduino with Java
- Meaning of *= in Java
- What is Java String interning?
- Rename a file using Java
- What is “String args[]”? parameter in main method Java
- “A java exception has occurred” when opening .jar
- How do I set environment variables from Java?
- Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 0 error in Java
- What’s the advantage of load() vs get() in Hibernate?
- What Java ORM do you prefer, and why?
- Always Round UP a Double
- Using Enum values as String literals
- “Actual or formal argument lists differs in length”
- TreeMap sort by value
- Encrypt Password in Configuration Files?
- Could not find method compile() for arguments Gradle
- How can I get the current stack trace in Java?
- java.util.zip.ZipException: error in opening zip file
- Getting warning “NDK is missing a ‘platforms” directory.’ with no NDK
- No appenders could be found for logger(log4j)?
- ArrayList<> cannot be resolved to a type
- Error occurred during initialization of VM (java/lang/NoClassDefFoundError: java/lang/Object)
- Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 0
- Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args) [duplicate]
- ArrayList<> cannot be resolved to a type
- Simple way to repeat a string
- Unreachable statement compile error in Java
- Reflection generic get field value
- java.lang.ArrayIndexOutOfBoundsException: 4 Error
- How to detect EOF in Java?
- Information about _JAVA_OPTIONS
- Two dimensional array list
- Must issue a STARTTLS command first
- Convert boolean to int in Java
- How to convert a String to CharSequence?
- Aspect Ratio with 800×480
- How do I convert a String to a BigInteger?
- How to set JAVA_HOME in Linux for all users
- What is ‘PermSize’ in Java?
- Jackson with JSON: Unrecognized field, not marked as ignorable
- How can I wait for 10 second without locking application UI in android [duplicate]
- Java error “Value of local variable is not used”
- Is there a way to end the program if statement is false?
- ArithmeticException: “Non-terminating decimal expansion; no exact representable decimal result”
- convert string to arraylist
in java - Java: Not a statement
- how to use drawArc()
- How to add RGB values into setColor() in Java?
- How do I enable index downloads in Eclipse for Maven dependency search?
- How to convert java.util.Date to java.sql.Date?
- Java: Variable is already defined in method