Most efficient way to order an array of Strings by frequency
问题 I have an array of Strings: String[] stringArray = {"x", "y", "z", "x", "x", "y", "a"}; What is the quickest/most efficient way to order this into a smaller Collection in order of how frequent each String is with its frequency? I though about using the String as a key in a HashMap<String,Integer> but this wouldnt be sorted in terms of frequency My other method i considered is using a TreeMap<Integer, String[]> with a list of Strings with that integer, but there seems a lot of checking