


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

An unpatchable Yubico two-factor authentication key vulnerability has broken the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices. The Feitian A22 JavaCard and other devices using Infineon SLB96xx series TPMs are also vulnerable.All

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.
