i have an arraylist named proteins. i need to find out and display which protein in the arraylist is repeated the most number of times. can anyone give me the code for it? some one suggested me to use maps but i have never worked with them. please help
hey thank you!! but i have a doubt. this will display all the entries along with the number of times each entry is repeated. i want only the one entry which is repeated the most number of times. how to do that???
The one that is repeated the most will be the entry with the highest count.
"If the facts don't fit the theory, get new facts" --Albert Einstein
Joined: May 16, 2011
yes i got that! but i have been asked to print only the most highly repeated entry and not the others, whereas here the print statements prints all the entries in the map along with the number of times they are repeated. i have to print just one entry ie the most repeating entry only. how to do that?
ankit chaubal wrote:yes i got that! but i have been asked to print only the most highly repeated entry and not the others, whereas here the print statements prints all the entries in the map along with the number of times they are repeated. i have to print just one entry ie the most repeating entry only. how to do that?
You modify the code ! It's not that hard so why don't you have a go rather than just waiting for someone to do it for you. You'll learn much more that way.
We really don't like to just hand out code. We much prefer YOU to write it, ask specific questions, and we will help you fix/adjust/tweak it as needed.
Hunter has given you the best advice so far - but I'd go a little further. Forget JAVA all together. Describe, in english, how you personally would find which element in a list occurs the most number of times.
For example, if I needed to sort a list of items, I might do it like this:
read the first element of the list, and remember it.
Read every other element, and see if it any greater than the one i remember, and if so, remember it instead.
when i get to the end of the list, I have the greatest element left in the list.
Write that one down in a NEW list.
Cross it out of the old list
Start over on the old list.
when all the elements are crossed off the old list, the new list is complete and sorted.
So, do the same thing but explain how you would find the element that appears the most number of times in a list. You can use a paper and pencil to keep track of stuff, if you want, but explain what you write down, and how you change it.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
subject: displaying the most highly repeated entry in an ArrayList