title: How do I print out my Hashmap in Java
body: <p>Okay so I have a hashmap of the class Stock, which basically has data about different stocks from yahoo that a user can enter. Each time they enter a new stock, I add that Stock class to the hashmap, and I don't know how to print out the whole hashmap and display everything entered so far</p>
  
  <pre><code>public class AS4stocks {
      static Map&lt;String, Stock&gt; mappin = new HashMap&lt;String, Stock&gt;();
  
      public static void main(String[] args) throws IOException {
  
          int menuchoice;
  
          do {
              Scanner in1 = new Scanner(System.in);
              System.out
                      .println("What would you like to do \n1) Print table\n2) Add a stock\n3) Do something else");
              menuchoice = in1.nextInt();
              switch (menuchoice) {
  
              case 1:
                  System.out.println(mappin);
                  break;
  
              case 2:
                  System.out.print("Enter the stock's ticker symbol\n");
                  String ticker = in1.next();
                  addstock(ticker);
                  break;
  
              case 3:
                  break;
  
              }
          } while (menuchoice != 0);
  
      }
  
      private static void Printtable(Map&lt;String, Stock&gt; mappin) {
              fo  
  
          }
  
      private static void addstock(String ticker) throws IOException {
          URL url = new URL("http://download.finance.yahoo.com/d/quotes.csv?s="
                  + ticker + "&amp;f=snd1ohgpvwm3m4&amp;e=.csv");
          URLConnection con = url.openConnection();
          InputStream is = con.getInputStream();
          BufferedReader br = new BufferedReader(new InputStreamReader(is));
  
          String line = null;
  
          Object[] otable = new String[11];
  
          int counter = 0;
  
          while ((line = br.readLine()) != null) {
              String str = line;
              StringTokenizer st = new StringTokenizer(str, ",\"");
              while (st.hasMoreTokens()) {
                  String adder = st.nextToken();
                  otable[counter] = adder;
                  if (counter == 0) {
                      System.out.println("-------------------" + adder
                              + "-------------------");
                      System.out.print("Ticker: ");
                  }
                  if (counter == 2) {
                      System.out.print("Company: ");
                  }
                  if (counter == 3) {
                      System.out.print("Open: ");
                  }
                  if (counter == 4) {
                      System.out.print("High: ");
                  }
                  if (counter == 5) {
                      System.out.print("Low: ");
                  }
                  if (counter == 6) {
                      System.out.print("Close: ");
                  }
                  if (counter == 7) {
                      System.out.print("Volume: ");
                  }
                  if (counter == 8) {
                      System.out.print("52 Week Range: ");
                  }
                  if (counter == 9) {
                      System.out.print("50 Day Average: ");
                  }
                  if (counter == 10) {
                      System.out.print("200 Day Average: ");
                  }
                  System.out.println(adder);
                  counter++;
              }
  
              Stock snew = new Stock(otable);
              mappin.put(ticker, snew);
  
          }
          System.out.println();
      }
  
      static class Stock {
          String compname;
          String ticker;
          String date;
          String open;
          String high;
          String low;
          String close;
          String volume;
          String range;
          String average50;
          String average200;
  
          public Stock(Object otable[]) {
              compname = (String) otable[0];
              ticker = (String) otable[1];
              date = (String) otable[2];
              open = (String) otable[0];
              high = (String) otable[1];
              low = (String) otable[2];
              close = (String) otable[3];
              volume = (String) otable[4];
              range = (String) otable[5];
              average50 = (String) otable[6];
              average200 = (String) otable[7];
  
          }
      }
  }
  </code></pre>