The Artima Developer Community
Sponsored Link

Java Answers Forum
Frequent

1 reply on 1 page. Most recent reply: Oct 15, 2003 12:43 AM by Alex S

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Mike

Posts: 1
Nickname: mosherguy
Registered: Oct, 2003

Frequent Posted: Oct 14, 2003 4:15 PM
Reply to this message Reply
Advertisement
I am quite new to java and am trying to write a program to find the most frequent number in an arraylist.
If you could explain the code in detal it would be helpful.
Thanks for any help


Alex S

Posts: 27
Nickname: andu
Registered: Mar, 2003

Re: Frequent Posted: Oct 15, 2003 12:43 AM
Reply to this message Reply
You can use a map object to store frequencies. This map will store mappings from number N to an Integer object (the frequency).


for each number N in arraylist
get the counter for N from map
if counter not exist yet, put it in the map [N->0]
increment counter


In the end, you get a map with all numbers from arraylist and with frequencies for each number.

Flat View: This topic has 1 reply on 1 page
Topic: Collision in games Previous Topic   Next Topic Topic: EJB

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use