title: How to get product details based on product category, in java HashMap?
body: <p>There is HashMap. I added all the product details in hashmap. I want to display the product details based on category. It means all same category products should be display. I am trying to create method for that. The method name is </p>
  
  <pre><code>public List&lt;Product&gt; getProductsBasedOnCategory(String category)
  {
  
  }
  </code></pre>
  
  <p>Please find below code. </p>
  
  <p>Product.java</p>
  
  <pre><code>public class Product {
  
      private long pid;
      private String pname;
      private String category;
      private float price;
      private long stock;
      private String remarks;
  
      public Product()
      {
  
      }
  
      public Product(long pid,String pname,String category,float price,long stock,String remarks){
          this.pid=pid;
          this.pname=pname;
          this.category=category;
          this.price=price;
          this.stock=stock;
          this.remarks=remarks;
      }
      public long getPid() {
          return pid;
      }
      public void setPid(long pid) {
          this.pid = pid;
      }
      public String getPname() {
          return pname;
      }
      public void setPname(String pname) {
          this.pname = pname;
      }
      public String getCategory() {
          return category;
      }
      public void setCategory(String category) {
          this.category = category;
      }
      public float getPrice() {
          return price;
      }
      public void setPrice(float price) {
          this.price = price;
      }
      public long getStock() {
          return stock;
      }
      public void setStock(long stock) {
          this.stock = stock;
      }
      public String getRemarks() {
          return remarks;
      }
      public void setRemarks(String remarks) {
          this.remarks = remarks;
      }
  
  }
  </code></pre>
  
  <p>DatabaseClass.java</p>
  
  <pre><code>public class DatabaseClass {
  
      private static Map&lt;Long, Product&gt; products=new HashMap&lt;&gt;();
  
      public static Map&lt;Long, Product&gt; getProduct()
      {
          return products;
      }
  
  }
  </code></pre>
  
  <p>ProductDao.java</p>
  
  <pre><code>private Map&lt;Long, Product&gt; products=DatabaseClass.getProduct();
  
  public ProductDaoImpl()
  {
      products.put(1L, new Product(1L,"TV","Entertinement",10000F,250L,"This is best TV!"));
      products.put(2L, new Product(2L,"Computer","Technology",20000F,350L,"My Computer name Hp and SONY ViVo!"));
      products.put(3L, new Product(3L,"DeskTopComputer","Technology",15000F,150L,"My Desktop Computer name Accer and SONY ViVo!"));
  }
  
  //Get All products
  public List&lt;Product&gt; getAllProducts() {
  
      return new ArrayList&lt;Product&gt;(products.values());
  }
  
  //Get product by product id
  public Product getProduct(long pid) {
  
      return products.get(pid);
  }
  
  //To Add the products 
  public Product addProduct(Product product) {
      product.setPid(products.size()+1);
      products.put(product.getPid(), product);
      return product;
  }
  
  //Update the product
  public Product updateProduct(Product product) {
      if(product.getPid()&lt;=0)
      {
          return null;
      }
      products.put(product.getPid(), product);
      return product;
  }
  
  // Delete the product
  public Product deleteProduct(long pid) {
  
      return products.remove(pid);
  
  }
  
  
  
  //Get the product by category
  public List&lt;Product&gt; getProductByCategory(String category) {
  
      if(products.size()&lt;=0)
      {
          return null;
      }
  
      else if(category.equals(products.get(Product))
      {
  
  
  
      }
  </code></pre>
  
  <p>I am trying a lot how to write code to get the value of model class in HashMap. 
  And how to write code for above getProductByCategory(String category). </p>