Topic: 排序的问题

  Print this page

1.排序的问题 Copy to clipboard
Posted by: gleamyshadow
Posted on: 2006-06-10 19:59

在给数组排序的时候,如果是一般数据类型数组,那么会根据数据的大小来排序,但是如果是Object类的数组,它是以什么标准来排序的?

2.Re:排序的问题 [Re: gleamyshadow] Copy to clipboard
Posted by: gip
Posted on: 2006-06-11 18:01

。。。飞机,大炮,坦克

你怎么排序?

解决这个问题后我想你自然会知道Object怎么排序了

3.Re:排序的问题 [Re: gleamyshadow] Copy to clipboard
Posted by: gleamyshadow
Posted on: 2006-06-12 22:31

哦,知道了,是先根据需要在每个Object里设定一个变量,然后通过这个变量来比较,好象是要覆盖一个CompareTo方法,对不对?

4.Re:排序的问题 [Re: gleamyshadow] Copy to clipboard
Posted by: ranchgirl
Posted on: 2006-06-13 01:52

Yes, that is one way to do it!!!!

compareTo() not CompareTo

You need to implements Comparable interface

See javadoc here

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html

5.Re:排序的问题 [Re: gleamyshadow] Copy to clipboard
Posted by: gleamyshadow
Posted on: 2006-06-13 20:19

Thanks,I have read it and found the answer,but as that you said,this is one way of do it,so I want to know what the ather ways are?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923