0% found this document useful (1 vote)
104 views

Collection Framework - Map Assignments

The document provides assignments to work with different Map implementations in Java, including HashMap, HashTable, and TreeMap. 1. The first assignment involves creating a HashMap to store country and capital pairs, and developing methods to save pairs to the map, retrieve capital or country by name, iterate through the map and create a new map with keys and values swapped, and retrieve all country names. 2. The second assignment involves creating a HashMap to store String keys and values, and implement methods to check for keys/values, and iterate through the key set. 3. The third assignment involves creating a Properties object to store Indian states and capitals, and iterate through the elements.

Uploaded by

sasirekha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
104 views

Collection Framework - Map Assignments

The document provides assignments to work with different Map implementations in Java, including HashMap, HashTable, and TreeMap. 1. The first assignment involves creating a HashMap to store country and capital pairs, and developing methods to save pairs to the map, retrieve capital or country by name, iterate through the map and create a new map with keys and values swapped, and retrieve all country names. 2. The second assignment involves creating a HashMap to store String keys and values, and implement methods to check for keys/values, and iterate through the key set. 3. The third assignment involves creating a Properties object to store Indian states and capitals, and iterate through the elements.

Uploaded by

sasirekha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Collection Framework – Assignment for Map

Map HashMap

1.1 Develop a java class with a instance variable CountryMap HashMap (M1) add a
method saveCountryCapital(String CountryName, String capital) , the method should
add the passed country and capital as key/value in the map M1 and return the Map
(M1). Key- Country Value - Capital India Delhi Japan Tokyo

1.2 Develop a method getCapital(String CountryName) which returns the capital for
the country passed from the Map M1 created in step 1.

1.3 Develop a method getCountry(String capitalName) which returns the country for
the capital name passed from the Map M1 created in step 1.

1.4 Develop a method which iterates through the map M1 and creates another map
M2 with Capital as the key and value as Country and returns the Map M2. Key –
Capital Value – Country Delhi India Tokyo Japan

1.5 Develop a method which iterates through the map M1 and creates an ArrayList
with all the Country names stored as keys. This method should return the ArrayList.
NOTE: You can test the methods using a main method.

2. Create a Collection called HashMap which is capable of storing String objects. The
program should have the following abilities a) Check if a particular key exists or not
b) Check if a particular value exists or not c) Use Iterator to loop through the map
key set

3. Map HashTable Properties


Write a program that will have a Properties class which is capable of storing some
States of India and their Capital. Use an Iterator to list all the elements of the
Properties.

4. Create a Collection “ContactList” using HashMap to store name and phone number
of contacts added. The program should use appropriate generics (String, Integer)
and have the following abilities: a) Check if a particular key exists or not b) Check if a
particular value exists or not c) Use Iterator to loop through the map key set
5. Implement the assignment 1 using TreeMap

6. Implement the assignment 1 using HashTable

You might also like