If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > List Sorting in JSP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-13-09, 03:43
akuccputsedut akuccputsedut is offline
Registered User
 
Join Date: Jun 2007
Posts: 35
List Sorting in JSP

I need help to sort this list to be alphabetically
I have an array list in this list name have different categories and color. I need to sort it by cotegories, color and sort by ascending order

the out come will be like this Ami is name, cat is categories and color is blue..(color that I mention is color font)
Ami-cat-blue
Aki-cat-blue
Bobo-cat-blue
Bobby-dog-yellow
riki-dog-yellow


Code:
for( int i=0; i < records.size(); i++) {

               if (((String) (((Attributes) records.elementAt(i)).get("animaltype").get())).equals("cat")) {
                   catList.add(records.elementAt(i));

               } else if (((String) (((Attributes) records.elementAt(i)).get("animaltype").get())).equals("dogs")) {
                   dogsList.add(records.elementAt(i));
               }

records.removeAllElements();

            records.addAll(catList);
            records.addAll(dogsList);
now I can sort it by color and categories but how to make name list in ascending order in jsp
Need HELP...thank you
__________________
**akuccputsedut**
Intelligent is Me!!But a little confusing
sometimes needs HELP!!
Reply With Quote
  #2 (permalink)  
Old 10-14-09, 06:52
dimis2500 dimis2500 is offline
Registered User
 
Join Date: Jan 2005
Posts: 362
You mean this?
Reply With Quote
  #3 (permalink)  
Old 10-16-09, 03:59
Pyrophorus Pyrophorus is offline
Registered User
 
Join Date: Aug 2009
Posts: 68
Maybe you could declare a method "compareTo" in your "Attribute" class:

Code:
int compareTo(Attribute toComp) {
 String s1 = toComp.animalName + "-" + toComp.animalType + "-" + toComp.color;
 String s2 = animalName + "-" + animalType + "-" + color;
 return s1.compareTo(s2);
}
Then you can sort Attribute as if they were String(s).

Hope this helps
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On