• [Java] 容器-06 TestArgsWords / BasicGeneric


    import java.util.*;
    
    public class TestArgsWords {
        private static final int ONE = 1;
    
        public static void main(String args[]) {
            Map<String, Integer> m = new HashMap<String, Integer>();
            for (int i = 0; i < args.length; i++) {
    
                if (!m.containsKey(args[i])) {
                    m.put(args[i], ONE);
                } else {
                    int freq = m.get(args[i]);
                    m.put(args[i], freq + 1);
                }
    
            }
            System.out.println(m.size() + " distinct words detected:");
            System.out.println(m);
        }
    }
    
    import java.util.*;
    
    public class BasicGeneric {
        public static void main(String[] args) {
            List<String> c = new ArrayList<String>();
            c.add("aaa");
            c.add("bbb");
            c.add("ccc");
            for (int i = 0; i < c.size(); i++) {
                String s = c.get(i);
                System.out.println(s);
            }
    
            Collection<String> c2 = new HashSet<String>();
            c2.add("aaa");
            c2.add("bbb");
            c2.add("ccc");
            for (Iterator<String> it = c2.iterator(); it.hasNext();) {
                String s = it.next();
                System.out.println(s);
            }
        }
    }
    
    class MyName implements Comparable<MyName> {
        int age;
    
        public int compareTo(MyName mn) {
            if (this.age > mn.age)
                return 1;
            else if (this.age < mn.age)
                return -1;
            else
                return 0;
        }
    }
    

  • 相关阅读:
    Cf序列化器-Serializer解析
    yield和return
    pymongo的使用
    Homebrew介绍和使用
    TypeError: expected string or bytes-like object
    JavaScript读取文本,并渲染在html
    反序相等
    打印邮票的组合
    打印对称平方数
    字符串按照原意输出
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786902.html
Copyright © 2020-2023  润新知