Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting the most frequent value.

 
Vincent Oh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"?

Thanks.
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's ok, i got it using SortedMap map = new TreeMap;

Cheers.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic