• HashMap的遍历


    package HashMapTest;
    
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Map.Entry;
    
    public class HashMapTest {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            HashMapTest test = new HashMapTest();
            test.input();
            test.get2();
        }
        
        private Map<Integer,String> map;
        private final String[] strArray = {"aaa","bbb","ccc","ddd","eee"};
        
        private void input()
        {
            map = new HashMap<Integer,String>();
            
            for(int i=0;i<5;i++)
            {
                map.put(i, strArray[i]);
            }
        }
        
        //遍历方法一 hashmap entrySet() 遍历
        private void get()
        {
            Iterator<Entry<Integer, String>> iterator = map.entrySet().iterator();
            while(iterator.hasNext())
            {
                Map.Entry<Integer,String> entry = (Map.Entry<Integer,String>)iterator.next();
                int key = entry.getKey();
                String value = entry.getValue();
                
                System.out.println("key="+key+",value="+value);
            }
        }
        
        //遍历方法二 JDK1.5中,应用新特性For-Each循环
        private void get2()
        {
            for(Map.Entry<Integer, String> entry:map.entrySet())
            {
                int key = entry.getKey();
                String value = entry.getValue();
                
                System.out.println("key2="+key+",value2="+value);
            }
        }
    }
  • 相关阅读:
    sort_action
    jedis
    ClassNotFoundException
    mysql-test-run.pl
    mysql 5.6 bug
    The basic principle of test case 修改引擎
    mysql 执行计划走索引
    mysql 执行计划走索引
    14.1.2 Checking InnoDB Availability 检查InnoDB 可用性:
    14.1.2 Checking InnoDB Availability 检查InnoDB 可用性:
  • 原文地址:https://www.cnblogs.com/Android9527/p/5394792.html
Copyright © 2020-2023  润新知