Adding multiple keys to a value in hashMap

Viewed 560

I currently have the following data in HTML form:

Year| car type     | # of cars sold
2001| Toyota-Camry | 242435
2000| Honda-Accord | 344423
2001| Honda-Accord | 555255
2000| Honda-Civic  | 342344
2008| Toyota-Prius | 666154
1996| Honda-Accord | 114526
2001| Toyota-Prius | 90234

In order to retrieve this data, I have a BufferedReader that reads in the lines from HTML. I skip a couple lines in the beginning before the data is present because there are empty spaces. So my code currently is

public class carSales {
    private Map<Integer, HashMap<Integer, String>> carSalesMan = 
            new HashMap <Integer, HashMap<Integer, String>>;

private void getcarTypes(String url) {
    try {
    URL urlz = new URL(url);
    URLConnection urlc = myURL.openConnection();
    BufferedReader line = new BufferedReader
    (new InputStreamReader(urlConnection.getInputStream()));

    String next;
    next = line.readLine(); 

    while (next.contains("</s>") {
        String[] parts = next.split(" ");

        if (carSalesMan.isEmpty() || carSalesMan.get(Integer.parseInt(parts[0])) == null {
            carSalesMan.put(Integer.parseInt(parts[0], new HashMap<Integer, String>());
            carSalesMan.get(Integer.parseInt(parts[0])).put(Integer.parseInt(parts[2]), parts[1])

        }
    }
    catch (IOException e) {
    }
}

the problem with this is that it seems to only store datas that have unique years. So the size of my carSalesMan variable would be 4 because I only have 4 unique years and they overwrite each other as the list goes down. Is there a simple way to add all the car types even if its the same year?

3 Answers
Related