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

 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 jdk5µÄ·ºÐÍÉùÃ÷

 ·ºÐÍÉùÃ÷¾ÍÊÇ·º·ºµÄÉùÃ÷ÀàÐÍ¡£ÎÒÃÇÓÃÆäËüµÄÓïÑÔ×öÒ»¸ö±È½Ï£º
JavascriptÉùÃ÷±äÁ¿£º var i= 1;var c = ‘char ’
VB ÉùÃ÷±äÁ¿£º dim i=1;dim c=’char’
Perl ÉùÃ÷±äÁ¿£º $i = 1; $c = ‘char’
ÕâЩ½Å±¾ÓïÑÔ£¬ÔÚÉùÃ÷±äÁ¿µÄʱºò£¬¸ù±¾¾Í²»ÏëjavaÄÇÑù»¹µÃÉùÃ÷ÀàÐÍ¡£ËûÃǵÄÀàÐÍÒѾ­× ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ