This would be easiest to do if you created a class with attributes of value and quantity (number of times it appears). Then sort your array of objects based on quantity.