🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #19653

Re: ���ʵ��String���͵�����

#19653
From: fireflyjava
Date: Wed, 31 Dec 2003 07:58
59 lines
2625 bytes
��ӡ�󣬻��Dz���������� 
�����Dz��ִ��룬�ܲ��ܰ�æ��һ��ûʲô�ط��㷨���? 
class comparator implements Comparator { 
public int compare(Object element1,  
Object element2) { 
String lower1 = element1.toString().toLowerCase(); 
String lower2 = element2.toString().toLowerCase(); 
return lower1.compareTo(lower2); 
} 
 
public Object[][] sort(Object num[][],int n) 
	{	comparator com=new comparator(); 
		for(int i=0; i<n; i++) 
		{ 
			 
			for(int j=n-1; j>i; j--) 
			{		 
			if(com.compare(num[j][0],num[j-1][0])>0); 
				{	 
				//System.out.println(	num[j][0].toString().trim()+".compareTo("+num[j-1][0
].toString().trim()+")::"+com.compare(num[j][0],num[j-1][0])); 
			 
					Object[] temp=num[j]; 
					num[j]=num[j-1]; 
					num[j-1]=temp;						 
							 
				} 
			}	 
		} 
		for(int f=0 ;f<n; f++) 
		{ 
			//System.out.println(f+":"); 
			System.out.println(f+":"+num[f][0].toString()); 
				 
		} 
		return num; 
		 
	} 
 
 
 
�� �� FoxTail. �Ĵ������ᵽ: �� 
: ת��վ: ZJUBBS!news.ccie.net.cn!Freecity 
: дһ����ʵ��comparable��ڣ�Ȼ��ʵ���Ǹ����� 
: �� �� fireflyjava.bbs@bbs.zju.edu.cn (fireflyjava) �Ĵ������ᵽ: �� 
: : ����String.compareTo��)�������Ƚ�String  
: : ����  
: : 2.compareTo��3������     -1(-1Ϊ����ֵ)  
: : 2.compareTo��100)         1  
: : 2.compareTo��96)         -7  
: : 2.compareTo��14654654)    1  
: : 3.compareTo��96)          6  
: : Ϊʲô��String.compareTo��)������ӵ�һλ�Ϳ�ʼ�Ƚϣ��������String���..
: : �أ�  
: : >>  .................<����ʡ��>............ 

--

�� ��Դ:���㽭��ѧ���ɰٴ�վ http://bbs.zju.edu.cn [FROM: fireflyjava]
Technical Details
Message-ID: <4A51kU$AGI@bbs.zju.edu.cn>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!ZJUBBS

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: f6cb0,ff0debc70be049e3
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2003-12-30 23:59:36 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!c03.atl99!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.ccie.net.cn!ZJUBBS
From: fireflyjava.bbs@bbs.zju.edu.cn (fireflyjava)
Newsgroups: cn.bbs.comp.lang.java
Subject: Re: ���ʵ��String���͵�����
Date: 31 Dec 2003 07:58:54 GMT
Organization: �㽭��ѧ���ɰٴ�
Message-ID: <4A51kU$AGI@bbs.zju.edu.cn>
X-Filename: Java/M.1072857534.A