AbstractMap.containsKey()
in Java is a method of the AbstractMap
class. The method is used to check whether a key is mapped into the AbstractMap
or not.
public boolean containsKey(Object key)
The function takes in one parameter.
key
: the key whose mapping is to be examined inside a map.The function returns a Boolean
value.
The function returns true
if AbstractMap
includes a mapping for key.
Otherwise, false
is returned.
import java.util.*; public class Abstract_Map_Class{ public static void main(String[] args) { // empty AbstractMap is created AbstractMap<Integer, String> temp_absMap1 = new TreeMap<Integer, String>(); // populating temp_absMap1 temp_absMap1.put(1, "Hello"); temp_absMap1.put(2, "from"); temp_absMap1.put(3, "Educative"); System.out.println("Displaying temp_absMap1 : " + temp_absMap1); System.out.println("** Checking temps_absMap1 to see if key 1 is present **"); System.out.println("Result : " + temp_absMap1.containsKey(1)); System.out.println("** Checking temps_absMap1 to see if key 4 is present **"); System.out.println("Result : " + temp_absMap1.containsKey(4)); } }
RELATED TAGS
CONTRIBUTOR
View all Courses