TreeMap class and message not understood issues - help please
Can anyone help with this one please?
The code is the start of a Map interface/TreeMap class to hold names as keys and addresses as values (both Strings).
I think the instance variable and the constructor are correct, but the addAddress method throws an error
Semantic error: Message addAddress( java.lang.String, java.lang.String ) not understood by class'java.util.TreeMap'.
I can only guess that I've overlooked something quite simple? The line at the end of the code should read
"Replaced "old address" with "new address" for "new name" and this should only display if the key already exists in the Map,
hence the if statement. The keys and values have been declared as Objects for future flexibility. Sorry if this is all blatantly obvious.
Also if I wanted to test this code and create an instance of the Addressbook class, what should my code look like?
public class Addressbook
private static Map<Object, Object> addresses;
this.addresses = new TreeMap<Object, Object>();
public static void addAddress(String name, String address)
System.out.println("Replacing " + addresses.remove(name) + " with "
+ addresses.get(name) + " for " + name);