java中的Map.Entry接口 [英] Map.Entry interface in java

查看:80
本文介绍了java中的Map.Entry接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.util.Map.Entry 我知道 中的公共静态接口 > java.util 包$ g $ b返回地图的集合视图但是到目前为止我对静态接口
感到困惑,因为它是Map.Entry它是一个内部接口如果是这样我们如何在java中有内部静态接口

java.util.Map.Entry as I know is a public static interface in java.util package that returns collection view of a map but as far now I am confused with the static interface and as it is Map.Entry is it an inner interface if so how do we have inner static interfaces in java

看看我很困惑的人请以任何可能的方式帮助我。

Look people I am confused Please help me in any possible way you can.

推荐答案

条目的定义恰好存在于 Map (由java允许)。 static 表示您不需要 Map 的实例来引用条目

The definition of Entry happens to live inside the definition of Map (allowed by java). Being static means you don't need an instance of Map to refer to an Entry.

最简单的方法是通过示例展示如何使用 Map.Entry 。以下是迭代地图的方法

It's easiest to show how to use Map.Entry by an example. Here's how you can iterate over a map

Map<Integer, String> map = new HashMap<Integer, String>();

for (Map.Entry<Integer, String> entry : map.entrySet()) {
    Integer key = entry.getKey();
    String value = entry.getValue();
    // do something with key and/or value etc
    // you may also alter the entry's value inside this loop via entry.setValue()
}

这篇关于java中的Map.Entry接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆