How to find entries in a HashMap java question How to find e

How to find entries in a HashMap java question?

How to find entries in a HashMap java question? static int Q11(HashMap input){//return the number of entries in the input map return 0;}

Solution

import java.util.HashMap;

public class HashMapExample {

   /**
   * by using size method of HashMap.
   *
   * @param input
   * @return int
   */
   static int Q11(HashMap<String, Double> input) {
       return input.size();
   }

   public static void main(String[] args) {
       /**
       * instance of hashmap
       */
       HashMap<String, Double> input = new HashMap<>();
       /**
       * inserting value into HashMap
       */
       input.put(\"1\", 1.0);
       input.put(\"1\", 6.0);
       input.put(\"2\", 2.0);
       input.put(\"3\", 3.0);
       input.put(\"4\", 4.0);
       input.put(\"5\", 5.0);
       System.out.println(\"Total number of enteries: \" + HashMapExample.Q11(input));
   }
}

/*****************output***********************/

Total number of enteries: 5

Thanks a lot

How to find entries in a HashMap java question? How to find entries in a HashMap java question? static int Q11(HashMap input){//return the number of entries in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site