HashMap in Java

import java.util.HashMap;
 
public class prices {
   public static void main(String[] args) {
      HashMap<String,Integer> prices = new HashMap<String,Integer>();
      prices.put("walmart", 88);
      prices.put("target", 100);
      prices.put("kmart", 77);
      prices.put("lowes", 90);
      System.out.println("walmart's price: " + prices.get("walmart"));
      System.out.println("Number of prices: " + prices.size());
      if (prices.containsKey("target")) {
         prices.remove("target");
         System.out.println("Record successfully removed.");
      }
      System.out.println("number of prices: " + prices.size());
   }
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.