• Apache通用集合MapIterator接口


    JDK Map接口很难作为迭代在EntrySetKeySet对象上迭代。 MapIterator提供了对Map的简单迭代。
    public class MapIteratorTester {
        public static void main(String[] args) {
            IterableMap<String,String> map = new HashedMap<String, String>();
            map.put("1", "One");
            map.put("2", "Two");
            map.put("3", "Three");
            map.put("4", "Four");
            map.put("5", "Five");
    
            MapIterator<String,String> iterator = map.mapIterator();
            while (iterator.hasNext()){
                Object key = iterator.next();
                Object value =iterator.getValue();
    
                System.out.println("key:"+key);
                System.out.println("value:"+value);
    
                iterator.setValue(value+"_");
            }
            System.out.println(map);
        }
    }

    结果:

    key:3
    value:Three
    key:5
    value:Five
    key:2
    value:Two
    key:4
    value:Four
    key:1
    value:One
    {3=Three_, 5=Five_, 2=Two_, 4=Four_, 1=One_}
    阁下何不同风起,扶摇直上九万里。
  • 相关阅读:
    001 windows下如何生成公钥和私钥
    函数基础
    各种推导式
    MySQL误删数据
    kafka 学习笔记
    Nginx 功能
    Nginx 到底可以做什么
    Nginx 到底可以做什么
    Shell的18条常用命令整理
    超详细 Nginx 极简教程
  • 原文地址:https://www.cnblogs.com/mlyun/p/10839715.html
Copyright © 2020-2023  润新知