当前位置:网站首页>There are three ways to traverse the map. Second, you know

There are three ways to traverse the map. Second, you know

2022-06-22 09:13:00 C_ x_ three hundred and thirty

package com.Cx_330.run;

import org.junit.Test;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Consumer;

public class CCC {
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1," Zhang San ");
        map.put(2," Zhang Xiaosan ");
        map.put(3," Zhangsanxiao ");
        map.put(4," Xiao Zhang San ");
        map.put(5," Three Xiaozhang ");
        Set<Integer> integers = map.keySet();
        for (Integer i:integers){
            System.out.println(" key : "+i+" value : "+map.get(i));
        }
        System.out.println("------------------------");
        Set<Map.Entry<Integer, String>> mp2 = map.entrySet();
        for (Map.Entry<Integer, String> x:mp2){
            System.out.println(" key : "+x.getKey()+" value : "+x.getValue());
        }
        System.out.println("------------------------");
        map.forEach((k,v)->System.out.println(" key : "+k+" value : "+v));
    }
}


原网站

版权声明
本文为[C_ x_ three hundred and thirty]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220910016049.html