import java.util.Hashtable; import java.util.Map; public class Frequence { public T mostFrequent(T[] tab) { Hashtable indexList = new Hashtable(); for (T element : tab) { indexList.put(element, indexList.get(element) == null ? 1 : ((Integer)indexList.get(element)) + 1); } T element = tab[0]; Integer count = indexList.get(tab[0]); for(Map.Entry entry : indexList.entrySet()) { if (entry.getValue() > count) { element = entry.getKey(); count = entry.getValue(); } } return element; } public static void main(String[] args) { Frequence f = new Frequence(); String[] tab = {"test", "test", "test", "12", "12", "12", "12"}; System.out.println(f.mostFrequent(tab)); } }