0
0

More than 1 year has passed since last update.

Map.Entry interface

Posted at

Entry interface is innner interface of Map interface
Entry is key + value .

public class Outer {
    public static void main(String args[]) {
        Map<String,Integer> mp = new LinkedHashMap<>();
        Entry<String,Integer> e = entry("sato-a",100);
        Entry<String,Integer> e1 = entry("sato-b",101);
        Entry<String,Integer> e2 = entry("sato-c",102);
        mp = Map.ofEntries(e,e1,e2);
        Set<Entry<String,Integer>> s = mp.entrySet();
        mp.entrySet().forEach((Entry<String,Integer> x) -> System.out.println(x.getKey() + ":" + x.getValue()));
        System.out.println("--------------------");
        for(Entry<String,Integer> en:s) {
            System.out.println(en.getKey() + ":" + en.getValue());
        }
    }
}
sato-a:100
sato-b:101
sato-c:102
--------------------
sato-a:100
sato-b:101
sato-c:102
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0