


How to determine whether the specified key exists in the map collection object in java
This method determines whether the Map collection object contains the specified key name. If the Map collection contains the specified key name, returns true, otherwise returns false.
Syntax:
containsKey(Object key)
Judgment method:
First define a map object, then add objects to the collection through the "put()" method, and then define a The specified key value can be judged through the "map.containsKey()" method.
Example:
public static void main(String[] args) { Map map = new HashMap(); //定义Map对象 map.put("apple", "新鲜的苹果"); //向集合中添加对象 map.put("computer", "配置优良的计算机"); map.put("book", "堆积成山的图书"); map.put("time", new Date()); String key = "book"; boolean contains = map.containsKey(key); //判断是否包含指定的键值 if (contains) { //如果条件为真 System.out.println("在Map集合中包含键名" + key); //输出信息 } else { System.out.println("在Map集合中不包含键名" + key); } }
Recommended tutorial: Getting started with java development
The above is the detailed content of How to determine whether the specified key exists in the map collection object in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
