博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java HashMap entrySet()方法与示例
阅读量:2529 次
发布时间:2019-05-11

本文共 1878 字,大约阅读时间需要 6 分钟。

HashMap类entrySet()方法 (HashMap Class entrySet() method)

  • entrySet() method is available in java.util package.

    entrySet()方法在java.util包中可用。

  • entrySet() method is used to return an entry (key-value pairs) that exists in this HashMap to be viewed in a Set.

    entrySet()方法用于返回此HashMap中存在的条目(键值对),以在Set中进行查看。

  • entrySet() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    entrySet()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • entrySet() method does not throw an exception at the time of returning entry set.

    返回条目集时, entrySet()方法不会引发异常。

Syntax:

句法:

public Set entrySet();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is Set, it returns mappings exist in this HashMap to be viewed in a Set.

方法的返回类型为Set ,它返回此HashMap中存在的映射以在Set中进行查看。

Example:

例:

// Java program to demonstrate the example // of Set entrySet() method of HashMap import java.util.*;public class EntrySetOfHashMap {
public static void main(String[] args) {
// Instantiates a HashMap object Map < Integer, String > map = new HashMap < Integer, String > (); // By using put() method is to add // key-value pairs in a HashMap map.put(10, "C"); map.put(20, "C++"); map.put(50, "JAVA"); map.put(40, "PHP"); map.put(30, "SFDC"); // Display HashMap System.out.println("HashMap: " + map); // By using entrySet() method is to // return the entry exists in this // HashMap to be viewed in a Set Set s = map.entrySet(); // Display set view System.out.print("map.entrySet(): "); System.out.println(s); }}

Output

输出量

HashMap: {50=JAVA, 20=C++, 40=PHP, 10=C, 30=SFDC}map.entrySet(): [50=JAVA, 20=C++, 40=PHP, 10=C, 30=SFDC]

翻译自:

转载地址:http://hnvzd.baihongyu.com/

你可能感兴趣的文章
winsocket客户端编程以及jmeter外部调用
查看>>
PHP基础知识------页面静态化
查看>>
zoj 3747 dp递推
查看>>
POJ 3740
查看>>
41025 ISD Assignment 2 Autumn 2019
查看>>
JavaScript跨域调用基于JSON的RESTful API
查看>>
js 右击事件
查看>>
POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)
查看>>
今天突然出现了Property IsLocked is not available for Login '[sa]',我太阳,下面有绝招对付它!...
查看>>
django-admin源码解析
查看>>
pc端字体大小自适应几种方法
查看>>
Linux--Linux下安装JDk
查看>>
Github windows客户端简单上手教程
查看>>
前端面试题:高效地随机选取数组中的元素
查看>>
[.NET] 使用 .NET Framework 開發 ActiveX Control
查看>>
Remote IIS Debugging : Debug your ASP.NET Application which is hosted on "Remote IIS Server"
查看>>
iframe 模拟ajax文件上传and formdata ajax 文件上传
查看>>
个人作品需要的报告
查看>>
7 月 2 日
查看>>
那些盒模型在IE6中的BUG们,工程狮的你可曾遇到过?
查看>>