zoukankan      html  css  js  c++  java
  • Day0202____集合复习

    HashMap  无序

    linkedHashMap 进入顺序排序

    TreeMap value排序

     

    package com_01_testfan_02_basic;
    
    import java.util.HashMap;
    import java.util.LinkedHashMap;
    import java.util.Map;
    import java.util.Set;
    import java.util.TreeMap;
    
    public class Day01_06_作业2 {
        
        
        public static void main(String[] args) {
            String testString="2342a2sfghgyu56asdasdaddddd";
            //0 //length()-1
            //char char_str =testString.charAt(testString.length()-1);
            //Map<String, Integer> mapcount = new LinkedHashMap<String, Integer>();
            //Map<String, Integer> mapcount = new TreeMap<String, Integer>();
            Map<String, Integer> mapcount = new HashMap<String, Integer>();
            
            for (int i = 0; i < testString.length(); i++) {
                //System.out.println(testString.charAt(i));
                String key =String.valueOf(testString.charAt(i));
                //如果map 不存在 value 1
                if(!mapcount.containsKey(key)) {
                    mapcount.put(key, 1);
                }else {
                //如果存在
                    int value = mapcount.get(key);
                    value +=1;
                    mapcount.put(key, value);
                }
            }
            
            Set<String> keySet =mapcount.keySet();
            for (String key : keySet) {
                System.out.println(key +" "+mapcount.get(key));
            }
            
            //System.out.println(char_str);
        }
    
    }
  • 相关阅读:
    Linux終端一行命令发送邮件
    团队冲刺2.4
    团队冲刺2.3
    团队冲刺2.2
    找水王
    评价win10自带输入法——微软拼音输入法
    梦断代码阅读笔记01
    团队冲刺2.1
    第十三周总结
    第十二周总结
  • 原文地址:https://www.cnblogs.com/wujianbo123/p/11031034.html
Copyright © 2011-2022 走看看