Is there any built in library that I can use for calculating median in java??
I was working with apache.commons.math for other statistical functions but median was nowhere to be found.
Thank you,
Put all the numbers into a list, sort the list, and take the middle value (or the average of the two middle values for even size). No calculations necessary
Which version of Apache Commmons Math are you using? There is a median class at least in 2.1 onwards (older version i am not sure). You can use it as:
Median median = new Median();
median.evaluate(values);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With