Use a TreeMap
with key as the Number and value is the number of occurences .Then use firstEntry()
and lastEntry()
for getting least and maximum value.TreeMap will sort the Integers in ascending order.
TreeMap tuples = new TreeMap();
For occurence of 2 ,simply use Integer tuples.get(2);