版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012081441/article/details/83659844
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
public class MapTest {
public static void main(String[] args) {
String[] data = {"hello","world","tt","hello","world","hello","world"};
Map<String,Integer> map = new HashMap<String,Integer>();
for(String str : data){
if(map.containsKey(str)){
map.put(str, map.get(str) + 1);
}else{
map.put(str, 1);
}
}
Iterator it = map.entrySet().iterator();
while(it.hasNext()){
Entry ex = (Entry) it.next();
System.out.println(ex.getKey() + ":" + ex.getValue());
}
}
}