aspose file tools
The moose likes Java in General and the fly likes Getting the most frequent value. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting the most frequent value." Watch "Getting the most frequent value." New topic

Getting the most frequent value.

Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
Let's say i got a few double[2] : {a, b}

{3.0, 3.0}, {1.0, 1.0}, {2.0, 2.0}, {3.0, 2.0}

How do I sort them based on "a" so that I can retrieve the most frequent "a"?

I tried the following:

which prints

But how do i retrieve the value 3.0 which is "a"?

Jayesh A Lalwani

Joined: Jan 17, 2008
Posts: 2507

So, you know how to get the frequency of each value of "a" right? Try to do this on paper, and go step by step

You got the first "a" in the list let's say A1, and you got the Frequncy of A1, let's call it F1. Now, let's say you get the second "a" in the list, let's call it A2, and you get the frequency of A2, let's call it F2. How will you know between A1 and A2, which one is more frequent? Once you did that, how will you do the same thing with A1, A2 and A3. How will you do that with A1, A2, A3... An.
Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
It's ok, i got it using SortedMap map = new TreeMap;


I agree. Here's the link:
subject: Getting the most frequent value.