If I have following map:
NavigableMap<Integer,String> nmap =
new TreeMap<Integer,String>();
nmap.put(3, "Three");
nmap.put(1, "One");
nmap.put(4, "Four");
nmap.put(5, "Five");
nmap.put(7, "Seven");
nmap.put(10, "Ten");
System.out.println(nmap);
// {1=One, 3=Three, 4=Four, 5=Five, 7=Seven, 10=Ten}
Is there a mechanism, that can allow me to print this, printing by index value, if index is smaller more than 1 from the following index print -(dash):
One,-,Three,Four,Five,-,Six,Seven,-,-,Ten
How would I write function for this?
I don’t have to print whole map to string I meant for each key/value pair
Here’s a generalized solution, that also does the concatenation. My generics knownledge is a bit dodgy, so don’t be surprised by the odd mistake: