The sets, which implement the interface Collection
of Java
, as ArrayList, LinkedList, HashSet, etc...
do not accept primitive types.
But nothing prevents you from declaring a Set<Double> seuSet
and then do seuSet.add(2.33)
, a primitive double. Java uses the Wrappers or wrappers when it happens.
Every primitive type in java has a Wrapper
correspondent:
int => Integer
long => Long
float => Float
double => Double
... assim por diante...
So when you try to add a primitive double to the array by doing so seuSet.add(2.33)
, actually Java runs the following: seuSet.add(new Double(2.33))
And for what you’re wanting, which is to take an average of the numbers, I see no problem doing it that way.