Click to See Complete Forum and Search --> : java list


WSro
12-13-2005, 07:55 AM
i jave to create a counter which counts the email messages that a user sent.

The DB table looks like this

user_id, email_msg.... etc

The method must return an Arraylist with users that send the most emails first.

I was wondering if you have any ideas how i go about and do that ?

CVP

Khalid Ali
12-13-2005, 02:08 PM
here is an idea...do a query to the table with *.
Then in your while(result.next()){
//do something like this


String lstUserId="";
List mainList = new ArrayList()
List subList = new ArrayList()
while(results.next()){
String currentUserId = results.getString("user_id");
if(lstUserId.equals("") {
lstuserId = currentUserId;
}else if(!lstuserId.equals(currentUserId) {
//here u can add each sub list to main list
subList.add(currentUserId);
mainList.add(subList);
} else{
subList.add(currentUserId);
}
}
//once all is done then u can iterate thru mainList and see which sub list has the most records..


The logic above is not tested at al..its something that came to my mind first..hope it helps