Login    Forum    Search    FAQ   Blog

Board index » Server Side Development » Java




 Page 1 of 1 [ 5 posts ] 



Author Message
 Post subject: How 2 count the grp f itms in s list
 Post Posted: Mon Oct 26, 2009 7:31 pm 
Offline

Joined: Sat Feb 21, 2009 11:54 am
Posts: 47
Hi I m havin a list say servics("bob","galy","david","galy");

I want 2 get each item nd it was count like a bob=1, galy=2,.. How could I do dis ?


Top 
 Post subject: Re: How 2 count the grp f itms in s list
 Post Posted: Mon Oct 26, 2009 7:32 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
They were in a list? Just iterate throu da list:

Code:
List<String> myList; //contains "bob," etc...
int index = 1;
for ( String name : myList ) {
   System.out.println(name + "=" + index);
   index++;
}


Top 
 Post subject: Re: How 2 count the grp f itms in s list
 Post Posted: Mon Oct 26, 2009 7:32 pm 
Offline

Joined: Sat Feb 21, 2009 1:08 pm
Posts: 549
How could u do it wid out the code? Look at da 1st name, then count how many times it displays up in da list.
Look at da second name, nd if it was diff than da 1st name, count how many no. of tyms dat one shows up in da
list. Repeat dat until you have counted every name.

There were otr (better) ways 2 do it, however dat's da most straight forward way, I think.


Top 
 Post subject: Re: How 2 count the grp f itms in s list
 Post Posted: Mon Oct 26, 2009 7:32 pm 
Offline

Joined: Sat Feb 21, 2009 11:06 am
Posts: 1794
Oh yeah I totaly mis interpreted da OP. I think that he/she meant "index," did not display da repeat "galy" in der.


Top 
 Post subject: Re: How 2 count the grp f itms in s list
 Post Posted: Mon Oct 26, 2009 7:33 pm 
Offline

Joined: Sat Feb 21, 2009 11:54 am
Posts: 47
could I get values in a Map wid the key as names nd value as Count f those.??


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 5 posts ] 




Board index » Server Side Development » Java


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron