Question Index

Write a program to check the given Map contains the given value or not.Use one of the Map interface methods.

Input (Map, Integer) Output (Boolean)
{A=1, B=2, C=3, D=4, E=5}, 5 true
{Lion=1, Tiger=2, Cat=3, Rabbit=4, Mouse=5}, 9 fasle
{Ferrari=1, Mercedes=2, BMW=3, Audi=4, Ford=3}, 7 false
null, 4 null

import java.util.*;

class IsContainsValue
    public static void main(String s[])
        Map<String, Integer> input = new TreeMap<String, Integer>();
        input.put("A", 1);
        input.put("B", 2);
        input.put("C", 3);
        input.put("D", 4);
        input.put("E", 5);
        System.out.println("The has value: " + hasValue(input, 2));


    public static Boolean hasValue(Map<String, Integer> input, Integer value) {




Topic: LinkedHashMap In Java with Code Example

Read this topic
Take test on this topic

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App