Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含重复单词的字符串,我需要计算字符串中唯一同时出现的重复单词。
String a="am abc am am am xyz as xyz xyz xyz xyz";
上面的字符串我需要计算am同时发生的字符串,即am 发生 3 次,xyz 发生 4 次,在此我只需要显示xyz=4 ,这是同时重复的最大值。谁能帮帮我。
am
1. Create a HashMap of Strings and Integer. 2. Split the given String with the delimiter and create an array of Strings[]. 3. Loop through the array of Strings[] and check if the String exists in HashMap, 3.1 if yes, increment the value by 1.
这里的关键词:
希望这可以帮助。