StringRelated { public static void charFrequency(String[] strArray) { if (strArray == null || strArray.length == 0) { return; } for (int i = 0; i < strArray.length; i++) { Map<Character, Integer> frequencyMap = new HashMap<>(); char[] charArray = strArray[i].toCharArray(); for (int j = 0; j < charArray.length; j++) { if (frequencyMap.get(charArray[j]) == null) { frequencyMap.put(charArray[j], 1); } else { frequencyMap.put(charArray[j], frequencyMap.get(charArray[j]) + 1); } } Map<Character, Integer> sortedMap = frequencyMap .entrySet() .stream() .sorted(Collections.reverseOrder(comparingByValue())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new)); System.out.println("\nstring is: " + strArray[i]); for (Map.Entry<Character, Integer> entry : sortedMap.entrySet()) { System.out.println("char is: " + entry.getKey() + ", frequency is: " + entry.getValue()); } } }  static void main(String[] args); static void printOddAndEvenInorderByTwoThread(); static int searchSubstring(String str1, String str2); static int searchMethod1(String str1, String str2); static int searchMethod2(String str1, String str2); static void charFrequency(String[] strArray); static int searchMaxLengthMethod1(String s, int k); static int searchMaxLengthMethod2(String s, int k); static void searchLongestRepeatedSubstringMethod1(String originStr); static String searchLongestRepeatedSubstringMethod2(String originStr); static boolean wordMatch(char[][] chars, int arrayWidth, String word);  }
@Test public void charFrequency() { String[] strArray = {"www.taobao.com", "taobao", "asdf123123"}; StringRelated.charFrequency(strArray); }