泛型和自动打包的综合运用
Posted lsswudi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了泛型和自动打包的综合运用相关的知识,希望对你有一定的参考价值。
下面是泛型和自动打包的综合运用
import java.util.List; import java.util.LinkedList; import java.util.Collections; import java.util.*; public class Test public static void main(String[] args) Map<String,Integer> m1 = new HashMap<String,Integer>();Map m2<String,Integer> = new TreeMap<String,Integer>(); //m1.put("one",new Integer(1)); m1.put("one",1); //m1.put("two",new Integer(2)); m1.put("two",2); //m1.put("three",new Integer(3)); m1.put("three",3); //m2.put("A",new Integer(1)); m2.put("A",1); //m2.put("B",new Integer(2)); m2.put("B",2); System.out.println(m1.size()); System.out.println(m1.containsKey("one")); System.out.println(m2.containsValue(1)); //(m2.containsValue(new Integer(1))); if(m1.containsKey("two")) //int i = ((Integer)m1.get("two")).intValue(); //int i = (Integer)m1.get("two"); int i = m1.get("two"); System.out.println(i);
import java.util.*; public class TestArgsWords //private static final Integer ONE = new Integer(1); 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); /* //Integer freq = (Integer)m.get(args[i]); int freq = (Integer)m.get(args[i]) == null ? 0 :(Integer)m.get(args[i]) ; //m.put(args[i],(freq == null ? ONE :new Integer(freq.intValue()+1))); m.put(args[i],freq == 0 ? ONE : freq + 1); */ System.out.println(m.size()+" distinct words detected"); System.out.println(m);
以上是关于泛型和自动打包的综合运用的主要内容,如果未能解决你的问题,请参考以下文章