zoukankan      html  css  js  c++  java
  • Java基础之Map学习代码示例二:

    import java.util.*;

    class MapTest
    {
        public static void main(String[] args)
        {
            String tmp = new String("sdfgzxcvasdfxcavdf");
            Map<Character,Integer> map = new TreeMap<Character,Integer>(new Comparator<Character>(){
                public int compare(Character c1,Character c2)
                {
                    return c1.compareTo(c2);
                }
            });
            
            for(Character c : tmp.toCharArray())
            {
                if(map.containsKey(c))
                {
                    Integer v = map.get(c);
                    map.put(c,v+=1);
                }
                else
                    map.put(c,1);
            }
            
            for(Iterator<Map.Entry<Character,Integer>> it = map.entrySet().iterator();it.hasNext();)
            {
                Map.Entry<Character,Integer> entry = it.next();
                System.out.print(entry.getKey()+"("+entry.getValue()+") ");
            }
        }
    }
  • 相关阅读:
    C#:正则表达式
    jsp:
    关于博客的设置
    登录注册案例—MongoDB数据库连接
    cookie封装
    博客样式
    自己的博客
    CentOS7 启动docker.service失败
    合并多个jar包,并通过私服依赖
    springboot+支付宝条码支付开发详解
  • 原文地址:https://www.cnblogs.com/cxmsky/p/2864760.html
Copyright © 2011-2022 走看看