public class Demo2 {
public static void main(String[] args) {
// 原字符串
String s = "China and Canada on Monday pledged to strengthen security cooperation at a high-level dialogue held in Beijing.It was the first China-Canada High-Level National Security and Rule of Law Dialogue, a mechanism established during Canadian Prime minister Justin Trudeau's visit to China from late August to early September.According to a joint statement released after the meeting, the two sides exchanged views on fighting terrorism, cyber crime, organized crime, consular affairs and other issues.The two sides have confirmed their future cooperation framework. Some common goals are expected to be reached under the framework, such as initiating a discussion on an extradition treaty and finalizing an agreement on sharing and returning recovered assets.The dialogue was co-chaired by Wang Yongqing, secretary-general of the Commission for Political and Legal Affairs of the Communist Party of China (CPC) Central Committee, and Daniel Jean, National Security Advisor to the Canadian Prime Minister.After the dialogue, Meng Jianzhu, head of the Commission for Political and Legal Affairs of the CPC Central Committee, met with Jean. Meng said he hopes cooperation in security and legal affairs, which has become an integral part of the China-Canada relationship, will become a new bright spot in the development of bilateral ties. ";
System.out.println(s);
// 替换之后的字符串
String s_new = s.replaceAll("[,.()-]", " ");
System.out.println(s_new);
// 使用字符串的方法,分割字符串
String[] split = s_new.split(" +");
for (String string : split) {
System.out.println(string);
}
// 把单词当做键,次数当做值存储在hashMap集合里面
HashMap<String, Integer> hashMap = new HashMap<>();
for (String string : split) {