Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static <T> Map<T, Integer> frequency(Collection<? extends T> collection) {
        Map<T, Integer> res = new TreeMap<>();
        for (T element : collection) {
            if (!res.containsKey(element)) {
                res.put(element, Collections.frequency(collection, element));
            }
        }
        return res;
    }
}