package 第六章实验;importjava.util.*;publicclass 实验六 {publicstaticvoidmain(String[] args){String str="If you want to change your fate,I think you must come to the woniu to learn";String[] strs=str.split("[ ,\n\r\t.;!?()]");//这个地方有多个分割器HashMap<String,Integer> map=newHashMap<>();for(int i=0;i<strs.length;i++){//String泛型默认初始值为null//Integer泛型默认初始值为0if(map.containsKey(strs[i])){int value=map.get(strs[i]);
value++;
map.put(strs[i], value);}else{
map.put(strs[i],1);}}Set<String> set=map.keySet();for(String key : set){Integer value=map.get(key);System.out.println(key+"->"+value);}}}
统计字符串中每个单词出现的次数,使用HashMap来实现package 第六章实验;import java.util.*;public class 实验六 { public static void main(String[] args) { String str="If you want to change your fate,I think you must come to the woniu to learn"; String [] strs=str.split("[ ,\n\r\t.