如果我有以下字符串数组。
String inStrings[] = {"A", "B", "C", "D", "E", "F", "G", "H", "A", "B", "C", "D", "E", "A", "B", "C", "D", "A", "B"};
这个数组随后传递给一个方法,我不确定如何继续。
static void getColdSearch(String[] inArray){
}
这个方法的作用是获取数组中重复最少的字符串,然后在输出中打印出五个重复最少的字符串。重复的字符串不必相邻,如果少于五个字符串,则所有字符串都应包含在输出中。例如,如果数组列表看起来像上面的示例,则输出应该类似于此。
F //(Occurs once)
G //(Occurs once)
H //(Occurs once)
E //(Occurs twice)
D //(if two different elements repeat the same number of times a random one of them should be printed)
我该怎么做?
Map
,将数组中的字母作为键,值为计数器。然后找到前五个最小值,就可以了。开始吧。 - AntonH