Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaÖеÄÅÅÐò±È½Ï·½Ê½£º×ÔÈ»ÅÅÐòºÍ±È½ÏÆ÷ÅÅÐò

¡¡¡¡ÕâÀïËù˵µ½µÄJavaÖеÄÅÅÐò²¢²»ÊÇÖ¸²åÈëÅÅÐò¡¢Ï£¶ûÅÅÐò¡¢¹é²¢ÅÅÐòµÈ¾ßÌåµÄÅÅÐòËã·¨¡£¶øÊÇÖ¸Ö´ÐÐÕâЩÅÅÐòË㷨ʱ£¬±È½ÏÁ½¸ö¶ÔÏó“´óС”µÄ±È½Ï²Ù×÷¡£ÎÒÃǺÜÈÝÒ×Àí½âÕûÐ굀 i>j ÕâÑùµÄ±È½Ï·½Ê½£¬µ«µ±ÎÒÃǶԶà¸ö¶ÔÏó½øÐÐÅÅÐòʱ£¬ÈçºÎ±È½ÏÁ½¸ö¶ÔÏóµÄ“´óС”ÄØ£¿ÕâÑùµÄ±È½Ï stu1 > stu2 ÏÔÈ»ÊDz»¿ÉÄÜͨ¹ý±àÒëµÄ¡£ÎªÁ˽â¾öÈçºÎ±È½ÏÁ½¸ö¶ÔÏó´óСµÄÎÊÌ⣬JDKÌṩÁËÁ½¸ö½Ó¿Ú java.lang.Comparable ºÍ java.util.Comparator ¡£
Ò»¡¢×ÔÈ»ÅÅÐò£ºjava.lang.Comparable
¡¡¡¡Comparable ½Ó¿ÚÖÐÖ»ÌṩÁËÒ»¸ö·½·¨£º compareTo(Object obj) £¬¸Ã·½·¨µÄ·µ»ØÖµÊÇ int ¡£Èç¹û·µ»ØֵΪÕýÊý£¬Ôò±íʾµ±Ç°¶ÔÏó(µ÷Óø÷½·¨µÄ¶ÔÏó)±È obj ¶ÔÏó“´ó”£»·´Ö®“С”£»Èç¹ûΪÁãµÄ»°£¬Ôò±íʾÁ½¶ÔÏóÏàµÈ¡£ÏÂÃæÊÇÒ»¸öʵÏÖÁË Comparable ½Ó¿ÚµÄ Student Àࣺ
public class Student implements Comparable {
private int id;

private String name;
public Student() {
super();
}
@Override
public int compareTo(Object obj) {
if (obj instanceof Student) {
Student stu = (Student) obj;
return id - stu.id;
}
return 0;
}
@Override
public String toString() {
return "<" + id + ", " + name + ">";
}
}
¡¡¡¡Student ʵÏÖÁË×ÔÈ»ÅÅÐò½Ó¿Ú Comparable £¬ÄÇôÎÒÃÇÊÇÔõôÀûÓÃÕâ¸ö½Ó¿Ú¶ÔÒ»×é Student ¶ÔÏó½øÐÐÅÅÐòµÄÄØ£¿ÎÒÃÇÔÚѧϰÊý×éµÄʱºò£¬Ê¹ÓÃÁËÒ»¸öÀàÀ´¸øÕûÐÍÊý×éÅÅÐò£º java.util.Arrays ¡£ÎÒÃÇʹÓà Arrays µÄ sort ·½·¨À´¸øÕûÐÍÊý×éÅÅÐò¡£·­·­ API Îĵµ¾Í»á·¢ÏÖ£¬ Arrays Àï¸ø³öÁË sort ·½·¨ºÜ¶àÖØÔØÐÎʽ£¬ÆäÖоͰüÀ¨ sort(Object[] obj) £¬Ò²¾ÍÊÇ˵ Arryas Ò²ÄܶԶÔÏóÊý×é½øÐÐÅÅÐò£¬ÅÅÐò¹ý³ÌÖбȽÏÁ½¸ö¶ÔÏó“´óС”ʱʹÓõľÍÊÇ Comparable ½Ó¿ÚµÄ compareTo ·½·¨¡£
public class CompareTest {
public static void main(String[] args) {
Student stu1 = new Student(1, "Little");
Student stu2 = new Student(2, "Cyntin");
Student stu3 = new Student(3, "Tony");
Student stu4 = new Student(4, "Gemini");

Student[] stus = new Student[4];
stus[0] = stu1;
stus[1] =


Ïà¹ØÎĵµ£º

JavaµÄʱ¼ä´¦Àí(Ðø)

¸ÅÊö
Èç¹ûÄãÖªµÀÔõÑùÔÚjavaÖÐʹÓÃÈÕÆÚ£¬ÄÇôʹÓÃʱ¼äºÍËü²Å²»¶àÒ»Ñù¼òµ¥¡£ÕâƪÎÄÕ¸æËßÄãÔõÑù°ÑËûÃǵIJî±ðÁªÏµÆðÀ´¡£Robert Nielsen»¹¸æËßÄãÔõÑùʹÓÃjavaÀ´¼ÆËãµÖ´ïº½°àºÍÖÆÔì¹ý³ÌµÄʱ¼ä¡£
×÷ÕߣºRobert Nielsen
·­Ò룺Cocia Lin
ÕâƪÎÄÕÂÊÇÔÚÎÒ·¢±í¹ýµÄ<¼ÆËãJavaʱ¼ä>(ÒëÕß:ÒѾ­·­ÒëÍê³É)µÄ»ù´¡Éϵġ£ÔÚÕâÀΠ......

JavaÊý¾Ý±¨±à³ÌÖ®×é²¥

ת×ÔÆäËûÍøÕ¾
ºËÐÄÌáʾ£ºÔÚÐÅϢʱ´ú£¬ÍøÂç¼¼ÊõÓ¦ÓÃÒѾ­ºÜÆÕͨ¡£ÆäÖкܶàÓ¦Óö¼ÒÀÀµÓÚ´ÓÒ»¸öÖ÷»úÏò¶à¸öÖ÷»ú»òÕß´Ó¶à¸öÖ÷»úÏò¶à¸öÖ÷»ú·¢ËÍͬһÐÅÏ¢µÄÄÜÁ¦£¬ÔÚInternet
ÉÏ·Ö·¢µÄÊýÄ¿¿ÉÄÜ´ïÊýÊ®Íǫ̀£¬ÕâЩ¶¼ÐèÒª¸ü¸ßµÄ´ø¿í£¬²¢ÇÒ´ó´ó³¬³öÁ˵¥²¥µÄÄÜÁ¦¡£Ò»ÖÖÄÜ×î´óÏ޶ȵØÀûÓÃÏÖÓдø¿íµÄÖØ
ÔÚÐÅϢʱ´ú£¬ÍøÂç¼¼ÊõÓ¦ÓÃÒѾ­ºÜÆÕÍ ......

java ¼Ì³Ðdzµ­

Çë¿´ÏÂÃæÒ»Àý£º
public class TestAbstract {
int count;
public void operation(){
System.out.println("count = " + (++count));
}
}
public class Test extends TestAbstract {
public static void main(String[] args) {
Test test = new Test();
TestAbstract testAb = new TestAbstract();
testAb.operati ......

java ²âÊÔ


<!--
/* Font Definitions */
@font-face
{font-family:ËÎÌå;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@ËÎÌå" ......

javaдµÄÒ»¸öËÀËøÀý×Ó

public class DeadLock {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final Object resource1 = "resource1";
final Object resource2 = "resource2";

Thread t1 = new Thread(){
public void run(){
syn ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ