package com.hui_words;
import java.util.HashMap;
public class test {
public static void main(String[] args) {
String s = "你 好 要,不 好.好 不 好 ( 很 好) 好 个 人 - 你 才 是 ";
System.out.println(s);
String replaceAll = s.replaceAll("[,.()-]", " ");
System.out.println(replaceAll);
String[] split = replaceAll.split(" +");
for (String string : split) {
System.out.println(string);
}
HashMap<String,Integer> hashMap = new HashMap<>();
for (String string : split) {
if (hashMap.containsKey(string)) {
Integer integer = hashMap.get(string);
hashMap.put(string, integer++);
}else {
hashMap.put(string, 1);
}
}
System.out.println(hashMap);
}
} |
|