Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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µÄÕâÌõ·

     ÎÒÓÐÒ»ÍòԪǮ£¬ÊǽèµÄ£¡ÎÒ½èÁËÕâÒ»Íò¿éÇ®×¼±¸È¥±±¾©¼ÌÐøѧϰ¡£
     ÎÒÊÇÒ»¸ö´óרÉú£¬²»ÈëÁ÷ÎÒѧУ£¡ËäÈ»ÎÒÏàÐÅÒ»¸öÈ˵ÄŬÁ¦ÄܸıäÃüÔË£¡ËùÒÔÎÒÒ»Ö±¶¼ÔÚŬÁ¦µÄѧϰJAVA¼¼Êõ£¬Ï£ÍûÄÜÔÚÕâÌõ·ÉÏ×ߵĸüÔ¶£¡ÎÒÓÐÅ®ÅóÓÑ£¬¶ÔÎҺܺã¬Ò²ºÜÖ§³ÖÎÒ£¡µ«ÎÒ´Ó¸ñÁ¦¿Õµ÷´ÇÖ°£¬ÎÒ¾ÍÑ¡ÔñÁËJA ......

javaÒì³£´¦Àí

Ö»Õë¶Ô²»Õý³£µÄÌõ¼þ²ÅʹÓÃÒì³£
Òì³£Ö»Ó¦¸Ã±»ÓÃÓÚ²»Õý³£µÄÌõ¼þ£¬ËüÃÇÓÀÔ¶²»Ó¦±»ÓÃÓÚÕý³£µÄ¿ØÖÆÁ÷¡£
ÏÂÃæÊÇÒ»¸öÓÃÒì³£×÷±éÀú½áÊøÌõ¼þµÄÀÄÓÃÒì³£µÄÀý×Ó£º
//horrible abuse of exceptions. Don't ever do this!
try{
int i=0;
while(true)a[i++].f();
}catch(ArrayIndexOutOfBoundsException e){ ......

Java °´×Ö½Ú½ØÈ¡´øÓкº×ÖµÄ×Ö·û´®µÄÒ»ÖÖ×ö·¨

Java °´×Ö½Ú½ØÈ¡´øÓкº×ÖµÄ×Ö·û´®µÄ½â·¨£¬ÍøÉÏÓв»ÉÙÌÖÂÛ¡£ÕâÀïÎÒÒ²¸ø³öÒ»ÖÖÎÒ×Ô¼ºµÄ´¦Àí£¬»ù±¾Ô­Àí»¹ÊÇͳ¼ÆÒª½ØÈ¡µÄ×Ö½ÚÊýÖÐÊDZíʾºº×ÖµÄ×Ö½ÚÊýÊÇ·ñÊÇżÊý¸ö£¬¼´ÊÇ·ñ¸ÕºÃ°üÀ¨ÁËÍêÕûµÄºº×Ö¡£
/**
 * ±à³Ì£º±àдһ¸ö½ØÈ¡×Ö·û´®µÄº¯Êý£¬ÊäÈëΪһ¸ö×Ö·û´®ºÍ×Ö½ÚÊý£¬Êä³öΪ°´×Ö½Ú½ØÈ¡µÄ×Ö·û´®¡£ µ«ÊÇÒª±£Ö¤ºº×Ö²»±»½Ø°ë¸ ......

JAVAÓë×ãÇò¶ÓµÄÏàËƵã

JAVAÓкöණ¶«
Ç°¼¸Ìì¿´ÁË¿´ ûÔõôͨÃ÷°×
½ñÌìÔ糿3µã45¿´ÁË»á ¹ú¼ÊÃ×À¼ ¿Í³¡ÌôÕ½ ÇжûÎ÷µÄ±ÈÈü
°¥Ñ½ ºÜˬ
ħÁ¦ÄñÖØ·µË¹Ì¹¸£ÇÅ
ÎÒ¾ÍÏë°¡  ÕâJAVA²»ÊÇÓиö»Ø·ÃµÄº¯ÊýÂð
ºÇºÇ ÍüÁ˽ÐɶÁË
°²ÇÐÂåµÙÔÚÃ×À¼Ê±ÆÚ¾­³£±»¶¯µÄ°¤µ½Ä§Á¦ÄñµÄ¹ú¼ÊÃ×À¼µÄ´òѹ
ÕâºÎ³¢²»ÊÇJAVAÀïÃæµÄÄǸö¼Ì³ÐÂð
»¹ÓÐ ½ñÌì¹úÃ×ÔÚ·æÏßÉÏʹ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ