You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by senthil Kumar <se...@tarangtech.com> on 2005/04/20 08:54:28 UTC

Help me.results of ArrayList

Hi all.,


Could you please help me.

I have one ArrayList called dataList. 
it contains    { 20,10,20,20,10,15,15,15,15} as a String.

Now i need the result of each element appears in how many times like

20==>3
10==>2
15==>4

as a arrayList or Hash  Map.

Please help me.


Thanks in advance.


regs
Senthil







This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient or received it in error, please contact the sender by reply e-mail and destroy all copies of the original message. Please do not copy it for any purpose or disclose its contents.

Copyright Tarang Software Technologies Pvt. Ltd. 2004. All rights Reserved

Re: Help me.results of ArrayList

Posted by Tom Ziemer <t....@dkfz-heidelberg.de>.
Hi,

why don't you just iterate over your list and write it into a HashMap - 
something like:

HashMap mp = new HashMap();
for(int i=0; i<list.size(); i++)
{
	
	String item = (String)list.get(i);
	if(mp.containsKey(item))
	{
		Integer count = (Integer)map.get(item);
		count ++; // maybe cast to int
	}
	else
	{
		map.put(item, new Integer(1));
	}
}

This isn't very sophisticated, but it should work.

Regards,
Tom

senthil Kumar wrote:
> Hi all.,
> 
> 
> Could you please help me.
> 
> I have one ArrayList called dataList. 
> it contains    { 20,10,20,20,10,15,15,15,15} as a String.
> 
> Now i need the result of each element appears in how many times like
> 
> 20==>3
> 10==>2
> 15==>4
> 
> as a arrayList or Hash  Map.
> 
> Please help me.
> 
> 
> Thanks in advance.
> 
> 
> regs
> Senthil
> 
> 
> 
> 
> 
> 
> 
> This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient or received it in error, please contact the sender by reply e-mail and destroy all copies of the original message. Please do not copy it for any purpose or disclose its contents.
> 
> Copyright Tarang Software Technologies Pvt. Ltd. 2004. All rights Reserved

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org