I am wondering if it is possible to print the keys and associated map values ββin separate lines. I am new to Java and maps. When I try to print using the regular println command, as on the last line, it prints the keys and value inside the curly brace and all on the same line. I know that this is probably a stupid question, but I struggled with it for a while and did not find a solution on the Internet or in any of my lectures. This is just a class that I created to try to get it to work before trying to implement it on a larger scale. Sorry in advance if my code or something else does not appear in the usual way, this is my first post.
import java.util.TreeMap; public class tester { public static void main(String[] args){ TreeMap<String, String> dir = new TreeMap<String, String>(); String key = "b"; String value = "2"; String key1 = "a"; String value2 = "1"; dir.put(key, value); dir.put(key1, value2); System.out.println(dir); } }
source share