I have to write a program who use collection for implementing a map in Java.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Create a type MapEntry that holds a key and a value.
Take some collection class and extend it with methods
put(Object key, Object value),get(Object key),remove(Object key)andcontainsKey(Object key). Parametrize it to be a collection of MapEntries.First, containsKey: Loop through your collection, looking for a MapEntry that has a key value corresponding to the given key. Return true if you found one, false otherwise.
Next, put: Loop through your collection, looking for a MapEntry with the same key. If you find one, replace the value. If not, create a new MapEntry with the key and value and add it to your collection.
get: Loop through your collection, looking for a MapEntry with the given key. If you find one, return the value, otherwise null.
remove: Loop through… if you find one, remove that map entry.
Done.