我有一個包含重複字的字符串,我需要計算同時發生的字符串中唯一的重複字。計數同時發生在字符串中的字
String a="am abc am am am xyz as xyz xyz xyz xyz";
上面的字符串我需要計數am
其中occures同時即上午occures 3時間和XYZ occures 4時間並在此我需要僅顯示XYZ = 4這是最大同時重複。任何人都可以幫助我。
我有一個包含重複字的字符串,我需要計算同時發生的字符串中唯一的重複字。計數同時發生在字符串中的字
String a="am abc am am am xyz as xyz xyz xyz xyz";
上面的字符串我需要計數am
其中occures同時即上午occures 3時間和XYZ occures 4時間並在此我需要僅顯示XYZ = 4這是最大同時重複。任何人都可以幫助我。
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.
關鍵詞這裏:
希望這有助於。
好了,你有什麼嘗試? –
「同時」可能是錯誤的詞(我看你不是英語母語的人,這很好)。也許你的意思是「連續」?另外,像這樣的SO問題確實需要顯示你已經嘗試了什麼,以及你有什麼確切的問題。 SO不是「爲我編碼」或「給我如何做到這一點的一般提示」網站。 – hyde