链表中基于字符串的排序 [英] String based sorting in linked list

查看:148
本文介绍了链表中基于字符串的排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是Java新手.如何根据特定字符串对链接列表进行排序?
我创建了一个包含两个元素的类,

1.名称
2.地址

而且我读了很多次这些元素

现在我要根据名称对它进行排序..

请帮助我..在此先谢谢您....

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....

推荐答案

Google是您的朋友:很好,经常拜访他.与在这里发布问题相比,他可以更快地回答问题.

http://www.ehow.com/how_2094980_sort-linked-list-java.html [ ^ ]
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[^]


在我看来,您已经实现了自己的List实现,如果它扩展了Java-List,则可以简单地使用Collections.sort():

void java.util.Collections.sort(list [,比较器])

使用比较器,您可以使用(匿名)比较器对象比较两个字符串.

在那里,您可以简单地返回stringLeft.compareTo(stringRight)(在检查StringLeft是否为null之后)...

干杯,
Arndt
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


这篇关于链表中基于字符串的排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆