Object-Oriented Programming with Java, part II – Exercise 6

Store the names and nicknames of the following people in this hashmap so, that the name is the key and the nickname is the value using only lower case letters.

My Code

Main

import java.util.HashMap;

public class Nicknames {

    public static void main(String[] args) {
        // Do the operations required here!
        HashMap<String, String> hashmap = new HashMap<>();
        
        hashmap.put("matthew", "matt");
        hashmap.put("michael", "mix");
        hashmap.put("arthur", "artie");
        
        System.out.println(hashmap.get("matthew"));
    }

}

Model Code

Main

import java.util.HashMap;

 

public class Nicknames {

 

    public static void main(String[] args) {

        // Do the operations required here!

        HashMap<String, String> nicknames = new HashMap<>();

        nicknames.put("matthew", "matt");

        nicknames.put("arthur", "artie");

        nicknames.put("michael", "mix");

        System.out.println(nicknames.get("michael"));

    }

 

}

Comments

Almost exactly the same.

Leave a comment