title: Populating a HashMap with an Array
body: <p>So I tried finding a tutorial on how to do this but nothing gets this complicated.  This is the first I am learning of HAshMaps so I am sure my solution should be easy, but I don't know how to do it.</p>
  
  <p>I am trying to use an Array to populate a HashMap, and when I run the program my print out shows up null, which indicates that it isn't populating for me.  Been working on this for two days, and am really lost and confused.</p>
  
  <p>I am trying to get my key "expenses" to be valued with a "type".  </p>
  
  <p>Edit:  I would like my case two to be a printout of 
  1: groceries
  2: Entertainment
  3: Etc.....</p>
  
  <pre><code>public static void main(String[] args) throws FileNotFoundException, IOException 
  {
      // TODO code application logic here
  //        HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
      HashMap&lt;String, List&lt;Expenses&gt;&gt; map = new HashMap&lt;&gt;();
      List &lt;Expenses&gt; expenseType = new ArrayList();
      double amount, totalAmount;
      int cmd, year, month, date;
      String type, resp;
      totalAmount = 0;
  
      String fname = JOptionPane.showInputDialog("Enter the name of the budget file, none if no file");
      if (fname.compareTo("none") !=0)
      {
          FileInputStream ist = new FileInputStream(fname);
          ObjectInputStream ifile = new ObjectInputStream(ist);
  
  
      }
      boolean done = false;
      while(!done)
      {
          resp = JOptionPane.showInputDialog("Enter a command from: \n" 
                  + "\t1:Add a new deduction\n"  //think its done
                  + "\t2:Add a new expense\n"  //this is done, but could be made better wit
                  + "\t3:Add a deposit\n"  //This is done
                  + "\t4:Deduction options\n"  
                  + "\t5:Expense Options\n"  
                  + "\t6:Total balances in bank\n"
                  + "\t7:quit");
          cmd = Integer.parseInt(resp);
  
           switch(cmd)
          {
              case 1:
  
  
              break;
  
              case 2:
              //Give the option to add new spending occurence.
              //Give option to choose from array of spending types.
              resp = JOptionPane.showInputDialog("Enter a command from: \n" 
                  + "\t1: Create a new expense\n"  //done
                  + "\t2: Choose from expense list\n"
                  + "\t3:quit");
              int cmd2 = Integer.parseInt(resp);
              switch (cmd2)
              {
                  case 1:
  
                   type = JOptionPane.showInputDialog("Enter the type of the expense:"); 
  
                      resp = JOptionPane.showInputDialog("Enter the amount of the expense:");   
                      amount = Double.parseDouble(resp);
                      resp = JOptionPane.showInputDialog("Enter the year of the expense:");
                      year = Integer.parseInt(resp);
                      resp = JOptionPane.showInputDialog("Enter the month of the expense:");
                      month =  Integer.parseInt(resp);
                      resp = JOptionPane.showInputDialog("Enter the date of the expense:");
                      date =  Integer.parseInt(resp);
  //                      List&lt;Expenses&gt; expenses = map.get(type);
                      // Does the map have a List for type?
                      if (expenseType == null) {
                       // No. Add one.
                       expenseType = new ArrayList&lt;&gt;();
                          map.put(type, expenseType);
                          }
                      Expenses e = new Expenses(type, amount, year, month, date);
                      expenseType.add(e);
  
  //                        map.put(type, new ArrayList(expenses));
                      map.put(type, expenseType);
  
                      break;
  
                  case 2:
  
                   //Use a hashmap to search through the ArrayLIst and print out options.
                      //How do I populate the HashMap?
                   type = null;
                   List&lt;Expenses&gt; typelist = map.get(type); //reads from map
                   System.out.println(typelist);
  
  
              break;
      }
  
  }
  
  }
  }
  }
  </code></pre>