The number of times the Map set app retrieves letters from a string. For example: String: "abcdekka27qoq", output format: a (2) B (1) k (2)..., mapabcdekka27qoq
Package com. swift; import java. util. hashMap; import java. util. iterator; import java. util. map; import java. util. map. entry; import java. util. set; public class Test3_String_char {public static void main (String [] args) {/** 4th question: the number of times letters in a String appear. For example: String: "abcdekka27qoq", output format: a (2) B (1) k (2 )... */String str = "abcdekka27qoq"; char [] charArray = str. toCharArray (); Map <Character, Integer> map = new HashMap <Character, Integer> (); // the first time, the same elements are automatically filtered out and put into map (char c: charArray) {map. put (c, 0);} Set <Character> set = map. keySet (); for (char c: set) {System. out. print (c + "(" + map. get (c) + ")");} // get the original array for the second time. Compared with map, if it contains num + 1, delete the incorrect one and add the correct one, add 1 more, delete the delimiters, and add the correct for (char c: c HarArray) {if (map. containsKey (c) {int num = map. get (c) + 1; map. remove (c); map. put (c, num) ;}} System. out. println (); for (Map. entry <Character, Integer> entry: map. entrySet () {System. out. print (entry. getKey () + "(" + entry. getValue () + ")");} System. out. println (); Set <?> EntrySet = map. entrySet (); Iterator <?> It = entrySet. iterator (); while (it. hasNext () {Entry <Character, Integer> entry = (Entry <Character, Integer>) it. next (); System. out. print (entry. getKey () + "(" + entry. getValue () + ")");}}}