Welcome to the Ranch
Were you given that code exactly as you wrote it? That is pretty dreadful style; the lack of indentation will mean you can easily get lost, and the lack of {} in lines 11‑13 can cause more confusion. The old
Sun Style Guide will tell you there is a better way to write that sort of code anyway. And public fields (lines 2‑3) is poor design.
Anyway, you have code which will work, however unreliably, and you know all about Comparable<T> and Comparator<T>? Remind yourself about object ordering in the
Java™ Tutorials. If you click the
“previous” link, you will find it tells you about Maps. That should tell you all you need to know about adding things to Maps. Remind yourself about how a
SortedMap works, and you are going to find what I sometimes say, that these things are actually easier to implement than they look at first sight.
I presume the details of the Map mean that the “K”s represent addresses and the “V”s the names of the occupants.