zoukankan      html  css  js  c++  java
  • 泛型和自动打包的综合运用

    下面是泛型和自动打包的综合运用

    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); 
    	}
    }
    
  • 相关阅读:
    css常用属性记录
    js字符串常用方法总结
    mongoose基本操作
    本地存储API
    历史相关API
    自定义播放器
    HTML5全屏操作API
    HTML5自定义属性操作
    HTML5类操作
    案例:3D切割轮播图
  • 原文地址:https://www.cnblogs.com/lsswudi/p/11412343.html
Copyright © 2011-2022 走看看