<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>爱周末 &#187; Map.containsKey</title>
	<atom:link href="http://zhoumo123.cn/tag/map-containskey/feed" rel="self" type="application/rss+xml" />
	<link>http://zhoumo123.cn</link>
	<description>知识分享，共同进步。zhoumo123.cn</description>
	<lastBuildDate>Thu, 07 Nov 2019 05:53:49 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.1</generator>
	<item>
		<title>Map.containsKey方法(判断Map集合对象中是否包含指定的键名)</title>
		<link>http://zhoumo123.cn/java/3614.html</link>
		<comments>http://zhoumo123.cn/java/3614.html#comments</comments>
		<pubDate>Thu, 26 Oct 2017 06:27:53 +0000</pubDate>
		<dc:creator><![CDATA[zhangc]]></dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[Map.containsKey]]></category>

		<guid isPermaLink="false">http://zhoumo123.cn/?p=3614</guid>
		<description><![CDATA[Map集合允许值对象为null，并且没有个数限制，所以当get()方法的返回值为null时，可能有两种情况，一种是在集合中没有该键对象，另一种是该键对象没有映射任何值对象，即值对象为null。因此，在Map集合中不应该利用get()方法来判断是否存在某个键，而应该利用containsKey()方法来判断。 该方法判断Map集合对象中是否包含指定的键名。如果Map集合中包含指定的键名，则返回true，否则返回false。 语法  containsKey(Object key)  &#160;]]></description>
				<content:encoded><![CDATA[<p>Map集合允许值对象为null，并且没有个数限制，所以当get()方法的返回值为null时，可能有两种情况，一种是在集合中没有该键对象，另一种是该键对象没有映射任何值对象，即值对象为null。因此，在Map集合中不应该利用get()方法来判断是否存在某个键，而应该利用<strong>containsKey()</strong>方法来判断。</p>
<p>该方法判断Map集合对象中是否包含指定的键名。如果Map集合中包含指定的键名，则返回true，否则返回false。</p>
<p><strong>语法  containsKey(Object key) </strong></p>
<pre class="brush: java; title: ; notranslate">

public static void main(String[] args) {

Map map = new HashMap();       //定义Map对象

map.put(&quot;apple&quot;, &quot;新鲜的苹果&quot;);      //向集合中添加对象

map.put(&quot;computer&quot;, &quot;配置优良的计算机&quot;);

map.put(&quot;book&quot;, &quot;堆积成山的图书&quot;);

map.put(&quot;time&quot;, new Date());

String key = &quot;book&quot;;

boolean contains = map.containsKey(key);    //判断是否包含指定的键值

if (contains) {         //如果条件为真

System.out.println(&quot;在Map集合中包含键名&quot; + key); //输出信息

} else {

System.out.println(&quot;在Map集合中不包含键名&quot; + key);

}

}
</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://zhoumo123.cn/java/3614.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
