我如何按字母顺序排序? [英] How Can I Sort Alphabetically?
问题描述
好吧基本上我有一个会员俱乐部满是会员,当我想要取回他们所有的名字
i使用这个代码,但我真正想做的是按字母顺序将它们全部带回来,我不能使用java lib的帮助我必须使用我自己的排序方法。在任何人向我发送链接到java docs之前我已经尝试过但无法弄明白。
OK basically i have a members club full of members and when i want to get all their names back
i use this code but what i really want to do is get them all back alphabetically, and i cant use the help of a java lib i have to use my own sort method. And before any one sends me links to java docs i have already tried but cannot figure it out.
/**
* List names.
*/
public void listNames() {
for (int i = 0; i < members.size(); i++) {
Member member = members.get(i);
member.getName();
StdOut.println(i + ":" + member.getName());
}
}
}
推荐答案
你应该可以采用复制它为家庭作业时的代码。
您的老师可以看到它是您的代码还是其他代码。
请检查API:
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#toArray() [ ^ ]
You should be able to adopt the code when you copy it for the homework.
Your teacher can see if it's your code or another ones.
Please check the API:
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#toArray()[^]
试试这个
Try this
public static void sortStringExchange( String x [ ] ){
Arrays.sort(x, new Comparator<string>() {
@Override
public int compare(String s1, String s2) {
return s1.compareTo(s2);
}
});
}
试试heapsort http://en.wikipedia.org/wiki/Heapsort [ ^ ] http://codereview.stackexchange.com/questions/32606/implementation- of-heap-sort [ ^ ]
希望这会有所帮助:)
BCD
Well try heapsort http://en.wikipedia.org/wiki/Heapsort[^] http://codereview.stackexchange.com/questions/32606/implementation-of-heap-sort[^]
Hope this helps :)
BCD
>
这篇关于我如何按字母顺序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!