Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am new in java. How can I sort a linked list on the basis of a particular string..?

I have created a class with two elements,

1. Name
2. Address

and I am reading these elements many times

Now I want to sort this on the basis of name..

Please help me .. Thanks in advance....
Posted
Comments
BroonoVilliam 15-Mar-11 0:26am    
Thanks to all...

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

http://www.ehow.com/how_2094980_sort-linked-list-java.html[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Mar-11 16:23pm    
Friendship is offered but not always accepted :-) my 5.
--SA
To me it seems, that you made your own Implementation of a List, if it extends the Java-List, then you can simply use Collections.sort():

void java.util.Collections.sort(list [, comparator] )

With the comparator you can use an (anonymous) Comparator object to compare the two Strings.

there you can simply return stringLeft.compareTo(stringRight) (after checking StringLeft for null, that is)...

Cheers,
Arndt
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900