title: How to get an object from a HashMap in Java
body: <p>I'm trying to get the speed of a Test object from a HashMap when given the key but I'm not quite sure how to do it. I tried this way but its wrong:</p>
  
  <pre><code>hash.values().getSpeed();
  </code></pre>
  
  <p>Any help? Thanks</p>
  
  <pre><code>class Test {
  
              private String id;
              private String name;
              private int speed;
  
              public Test(String id, String name, int speed) {
                  this.id = id;
                  this.name = name;
                  this.speed = speed;
  
              }
  
              public String getId() {
                  return id;
              }
  
              public String getName() {
                  return name;
  
              }
  
              public int getSpeed() {
                  return speed;
              }
          }    
      public class Driver {    
      public static void main(String[] args) {
          HashMap&lt;String, Test&gt; hash = new HashMap&lt;String, Test&gt;();
  
              Test c1;
              Test c2;
  
              c1 = new Test("Z", "B", 4);
              c2 = new Test("Y", "D", 7);
              hash.put("A", c1);
              hash.put("C", c2);
      }
  }
  </code></pre>