[code]
public static void main(String[] args) {
// TODO auto-generated method stub
    String [] array = {"y","x","x","y","z","y","x","y","z","z"};
    List<String> list = new ArrayList<>(Arrays.asList(array));
    TreeSet<String> ts = new TreeSet<>(list);
    for(String s : ts) {
        int count = 0;
        for(String ss : list) {
            if(s.equals(ss)) {
                count++;
            }
        }
        System.out.println(s + " " + count);
    }
}
[Output result] x 3 y 4 z 3
[point] -The set of the collection was used so that the output result would not be displayed in duplicate. -I used TreeSet because I wanted to display in alphabetical order. -Arrays.asList () returned the array as a list.
Recommended Posts