Question Index

Write a program to identify those keys whose value is null in the given hash map.

Input (Hash Map) Output (String List)
{key4=>"how", key3=>null, key7=>null, key5=>"Hello", key6=>"Hai", key2=>"you", key1=>null, key8=>"are"} [key3, key7, key1]
{key4=>null, key3=>"value1", key6=>null, key2=>"?", key1=>"", key8=>null, key7=>null, key9=>"are"} [key4, key6, key8, key7]
{key4=>"how", key3=>"'", key6=>"nul", key2=>"Hello", key1=>null, key8=>"you", key7=>"nu1l", key9=>null} [key1, key9]
{key10=>null, key3=>null, key6=>"nill", key2=>"ull", key1=>"nu1l", key8=>"you", key7=>null, key9=>"nu11"} [key10, key3, Key7]

import java.util.*;
class GetKeysWithNullValues
    public static void main(String s[])
        Map<String, String> inputMap = new HashMap<String, String>();
        inputMap.put("key1", "Hai");
        inputMap.put("key2", "Hello");
        inputMap.put("key3", null);
        inputMap.put("key4", "how");
        inputMap.put("key6", null);
        inputMap.put("key7", null);
        inputMap.put("key8", "you");
        inputMap.put("key9", "are");
        inputMap.put("key9", "null");
        System.out.println("The keys are : " + getKeysListWhoseValueIsNull(inputMap));


    public static List<String> getKeysListWhoseValueIsNull(Map<String, String> inputMap) {




Topic: Java HashMap Implementation

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App