Containskey Method -- determines whether the specified key name is included

Source: Internet
Author: User

The containskey method is used to determine whether the map set object contains the specified key name.

Syntax Boolean containskey (Object key)

Return Value: If the map set contains the specified key name, true is returned; otherwise, false is returned.

Parameter: key is the key name object of the map set to be queried.

In this example, the hashmap class is used to create a map set object, add several elements to the set, and call the containskey method to check whether the specified key name is included.

Public static void main (string [] ARGs ){

Map map = new hashmap ();

Map. Put ("apple", "fresh apple"); // Add data to the list

Map. Put ("computer", "computer with excellent configuration"); // Add data to the list

Map. Put ("book", "books stacked into mountains"); // Add data to the list

String key = "book ";

Boolean contains = map. containskey (key );

If (contains ){

System. Out. println ("include key name in map set" + key );

} Else {

System. Out. println ("the key name is not included in the map set" + key );

}

}

Containskey Method -- determines whether the specified key name is included

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.