I am trying to make a HashMap such that the keys are months of the year and the values are names of peoples who's birthday it is in that month. I am quite stuck and don't know exactly what's wrong. Help is much appreciated.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class BirthdayStore {
HashMap<String, List<String>> map = new HashMap<String, List<String>>();
public BirthdayStore() {
HashMap<String, List<String>> map = new HashMap<String, List<String>>();
}
public boolean containsKey(String key) {
if(map.containsKey(key)) {
return true;
}
return false;
}
public void put(String key, String word) {
if(!map.containsKey(key)) {
ArrayList<String> arraylist = new ArrayList<String>();
arraylist.add(word);
}
else{
ArrayList<String> arraylist = (ArrayList<String>) map.get(key);
arraylist.add(word);
}
}
public List<String> get(String key) {
return map.get(key);
}
public static void main(String[] args) {
BirthdayStore k = new WordStore();
k.put("september","jack" );
k.put("september","josh" );
k.put("january","james");
System.out.println(k.get("september"));
}
}
Currently, my output is null.