Below code makes me to add objects in the list. and also it displaying the elements in the list. (Output:p1,p2,p1,p4,p5)
Now i need to count like p1 occured twice and p2,p4,p5 occured once.
What is your question? Could you elaborate on that a bit?
yekkala krishna
Ranch Hand
Joined: Mar 04, 2007
Posts: 105
posted
0
hi somnath,
good to see your reply.
following is my list:
List: {p1,p2,p1,p4,p5,p4,p5}
now i want to display count of each object occured in the list.(Each object compare with the other elements in the same list)
like p1- 2 times,p2-1 time,p4-2 times,p5-2 times
regards,
rama
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
posted
0
You can do a search of individual elements in the ArrayList and see how many times they appear and add the values to another HashMap and finally print the results of the HashMap.
yekkala krishna
Ranch Hand
Joined: Mar 04, 2007
Posts: 105
posted
0
Hi somnath,
thanks for your reply.
could you please write the code for counting.
You were given a pretty good hint on how to do this--use a map to store the count of each particular list item. Are you having a specific problem with maps, or something different?
We really don't want people to hand out solutions. Many folk who ask questions are students. If solutions were handed out, it would be too easy for someone to do the unethical thing of copying the work of someone else and handing it in as their own. Further, the best way to learn is to do it yourself. Come back and ask questions and post the code you've written to try implementing the suggestions (and please use code tags when you do).
But don't expect anyone to simply hand you the answer.
Also, while this may be important to you, it's not to anyone else here. anyone who replies in your thread is giving up their own valuable time to offer you the best help they can. Saying that this is really important to you makes it sound like you feel your time is more valuable than everyone else, and that tends to turn people off to where they don't want to help you anymore.
Never ascribe to malice that which can be adequately explained by stupidity.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
4
posted
0
yekkala krishna wrote:Hi Ritchie,
That's okay.
No, it isn't, but David and Fred have already given far better responses than I would have, so I shall keep quiet.