public static void main(String[] args) {
String str="good good study, day day up.";
String[] str2=str.split("[, .]+");
System.out.println(Arrays.toString(str2));
str=str.replaceAll("[^a-zA-z]+", "");//利用正则去除里面的非字母字符
// System.out.println(str);
Map<Character,Integer> map=new HashMap<Character,Integer>();//新建一个map集合
for(int i=0;i<str.length();i++){
char c=str.charAt(i);
if(map.containsKey(c)){
map.put(c, map.get(c)+1);//如果有重复的字母,让value的数值加1
}else{
map.put(c, 1);//有重复的就让放进map集合里面
}
}
System.out.println(map);
网友评论