Java文字列グループ統計


public class TestMain {
	 
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
 
		   
		ArrayList<String> aaa = new ArrayList<String>();
		aaa.add(" ");
		aaa.add(" ");
		aaa.add("a");
		aaa.add(" "); 
		
	        int differentCount = 0;   
	        Map<String,Integer> map = new HashMap<String,Integer>();   
	        for(int i=0;i< aaa.size() ;i++){      
	            String c = aaa.get(i);
	            if(map.containsKey(c)){   
	                map.put(c, map.get(c).intValue()+1);   
	            }else{   
	                map.put(c, new Integer(1));   
	            }   
	        }   
	        Iterator<String> it = map.keySet().iterator();   
	        while(it.hasNext()){   
	            String tmpc = it.next();   
	            differentCount++;   
	            System.out.println(tmpc+"="+map.get(tmpc));   
	        }   
	        System.out.println("differentCount="+differentCount);   

	
	}

	
    
	 
}