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

Java ==Óëequals()µÄÇø±ð

 ÎÒÃÇÀ´½éÉÜһϠ£½£½ºÍequals()µÄÇø±ð£¬£½£½ÊÇÏàµÈ£¬equals()Ò²ÊÇÏàµÈ¡£ÕâÁ½¸ö´ÊµÄÇø±ðÊÇʲôÄØ£¿ÕâÊÇÕÒ¹¤×÷ʱºÜ¶àÃæÊÔ¹ÙµÄÎÊÌâ¡£ÎÒÃÇÀ´½â´ðһϡ£Ê×ÏÈÎÒÃÇ¿´Õâô¸öÀý×Ó¡£Êµ¼ù£º
public class TestEquals {
public static void main(String[] args) {
MyDate date1 = new MyDate(14, 3, 1976);
MyDate date2 = new MyDate(14, 3, 1976);
if ( date1 = = date2 ) {
System.out.println("date1 is identical to date2");
} else {
System.out.println("date1 is not identical to date2");
}
if ( date1.equals(date2) ) {
System.out.println("date1 is equal to date2");
} else {
System.out.println("date1 is not equal to date2");
}
System.out.println("Éè date2 = date1;");
date2 = date1;
if ( date1 == date2 ) {
System.out.println("date1 is identical to date2");
} else {
System.out.println("date1 is not identical to date2");
}
}
}
Õâ¸öÀý×ÓÖеÄMyDateÀà´úÂëÈçÏÂ
public class MyDate {
private int day;
private int month;
private int year;
public MyDate(int day, int month, int year) {
this.day = day;
this.month = month;
this.year = year;
}
public boolean equals(Object o) {
boolean result = false;
if ( (o != null) && (o instanceof MyDate) ) {
MyDate d = (MyDate) o;
if ( (day == d.day) && (month == d.month)
&& (year == d.year) ) {
result = true;
}
}
return result;
}
public int hashCode() {
return (day ^ month ^ year);
}
}
½«ÕâÁ½¸öÀà·ÅÖõ½Í¬Ò»¸öÎļþ¼ÐÖУ¬Ö»ÐèÒª±àÒëTestEqualsÀ࣬¾Í¿ÉÒÔ½«MyDateһͬ±àÒëÁË¡£È»ºóÖ´ÐÐjava TestEquals²é¿´½á¹û¡£Èçͼ28-1Ëùʾ
ͼ28-1
Ò²¾ÍÊÇ˵date1 = = date2 ËäÈ»¶¼ÊÇnew MyDate(14, 3, 1976);µ«ÊÇnewÁËÁ½´Î¾ÍÊÇÁ½¸ö¶ÔÏóÁË£¬²»ÄÜ£½£½ÁË¡££½£½ÊÇÖ¸ÒýÓÃÊÇ·ñÏàͬ¡£
ÄÇôÓÃequals()ÄØ£¬equals()ÊÇObjectÀïµÄ·½·¨£¬ÈκζÔÏ󶼼̳ÐObject¡£ËùÒÔequals()·½·¨Ò²ÊÊÓÃÓÚËùÓеÄÀࡣΪʲôÕâ»Ødate1ºÍdate2¾ÍequalsÁËÄØ£¿equals£¨£©ÊÇÖ¸ÖµÊÇ·ñÏàµÈ¡£ÒòΪ¶¼ÊÇ£¨14£¬3£¬1976£©ËùÒÔÏàµÈ¡£
ÎÒÃÇ°Ñdate1¸³Öµ¸ødate2£¬½á¹ûµ±È»ÊÇ£½£½ÁË£¬¶¼ÒѾ­°ÑÒýÓø³¸øËüÁË¡£»¹Äܲ»£½£½Âð£¿
-
×ÊÁÏÒýÓÃ:http://www.knowsky.com/538995.html


Ïà¹ØÎĵµ£º

javaÈëÃÅ

 Javaѧϰ´ÓÈëÃŵ½¾«Í¨ 
Ò»¡¢ JDK (Java Development Kit) 
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......

¼¸ÖÖ³£¼ûµÄÊý¾Ý½á¹¹µÄJAVAʵÏÖ

 ITree
package utility.structure.def;
/**
*
* @author odie.tang
*
* @version 1.0 10/30/09
*/
public interface ITree<E>{

E getData();

E remove();

void setData(E e);

int getDepth();

int getLevel();

ITree<E> getRoot();

ITree<E> get ......

JavaÖظ´Ï´ÅÆ

 import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class ShuffleTest {
  public static void main(String args[]) {
    String simpsons[ ......

ѧjavaµÃÕâÑùѧ£¬Ñ§Ï°¶«Î÷ȷʵҲµÃÕâÑù¡¾×ª¡¿

    Èí¼þ¿ª·¢Ö®Â·ÊdzäÂú¾£¼¬ÓëÌôս֮·,Ò²ÊdzäÂúÏ£Íû֮·¡£JavaѧϰҲÊÇÈç´Ë£¬Ã»Óнݾ¶¿É×ß¡£ÃÎÏëÏñ¡¶ÌìÁú°Ë²¿¡·ÖÐÐéÖñÒ»Ñù±»ÎÞÑÂ×Óõ®õ­¹à¶¥¶øÇáËÉ»ñµÃÒ»¼××Ó¹¦Á¦£¬ÊǺܲ»ÏÖʵµÄ¡£Ã¿ÌìÑöÌì´ó½Ð"ÌìÉñ°¡£¬Çë´Í¸øÎÒÒ»±¾¿û»¨±¦µä°É"£¬Êâ²»Öª¼´Ê¹Äã»ñµÃÁË¿û»¨±¦µä£¬³ýÁËÊÜ×Ô¹¬ÆäÉíÖ®¿àÍ⣬ÄãÒ²²»Ò»¶¨³ÉµÃÁË"¶«·½² ......

Java½Ó¿ÚµÄ×÷Óü°ÊµÀý

 -
½üÈÕÔÚ±à³ÌÖÐÓõ½½Ó¿Ú֪ʶ,ÓÉÓڿα¾ÖжԽӿÚÃèÊö½ÏÉÙ,ËùÒÔÏë´ÓÍøÉϲéÕÒ×ÊÁÏ,µ«ÍøÉϵÄ×ÊÁÏ´ó¶àÒ²Ö»ÊÇÈß³¤µÄÃèÊö,ËùÒÔÔÚ´ËÌṩһ×Ô¼ºÐ´µÄʵÀý,¹©´ó¼Ò²Î¿¼:
Ô­ÌâÊÇÕâÑùµÄ£ºÔÚjavaÖУ¬¶¨ÒåÒ»¸ö½Ó¿Ú£¬ÉùÃ÷¼ÆË㳤·½ÐÎÃæ»ýºÍÖܳ¤µÄ³éÏó·½·¨£¬ÔÙÓÃÒ»¸öÀàȥʵÏÖÕâ¸ö½Ó¿Ú£¬ÔÙ±àдһ¸ö²âÊÔÀàȥʹÓÃÕâ¸ö½Ó¿Ú¡£
Ê×ÏÈ£¬½Ó¿Ú±ØÐ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ