标签:
import java.util.HashMap; public class map1 { public static void main(String[] args) { String[] array = {"a","b","a","b","c","a","b","c","b"}; HashMap hm = new HashMap(); for (String str : array) { if(hm.containsKey(str)) { hm.put(str, (int)hm.get(str)+1); } else hm.put(str, 1); } System.out.println(hm); } }
给定字符串数组,用map的key保存数组中字符串元素,value保存字符串元素出现次数,最后统计个字符串元素出现次数
标签:
原文地址:http://www.cnblogs.com/masterlibin/p/4774296.html