File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Searching inside a collection of user objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Searching inside a collection of user objects" Watch "Searching inside a collection of user objects" New topic
Author

Searching inside a collection of user objects

H Ritwick
Greenhorn

Joined: Mar 15, 2006
Posts: 18
Hi folks,
Pls suggest a good way of doing the below requirement.
I have a collection of userprofile objects (around 500..not in order).
I need to display these on a jsp(easy part)..which has filter keys like
a-h,I-P,Q-z like filters on the page. On click of any of the links I need to display the user names starting with I thro P in asc order.
I am thinking of using comparator for this.
compare(obj1,obj2)
Profile p1 = (Profile)obj1;
Profile p2 = (Profile)obj1;
then take the substring of user name's first char from p1 and p2
then if c1 > 'A' and c1 < 'H' return 1
else if c1 < 'A' and c1 > 'H' return -1
else if equal return 0

Is this a good way of doing this..Please suggest.
Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I would either :
1. Go through all user and extract those whose name begins with I-P
2. Sort the new list
Or
1. Manage all users in a sortable list (e.g. a SortedSet)
2. Extract users whose name begins with I-P

The compare() should return something like :
return p1.getName().compareTo(p2.getName())


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching inside a collection of user objects
 
Similar Threads
Package
finding closest point
Passing a value from Javascript to JSP
How to group these JLabels?
How to (re)paint an AWT applet faster