欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java中"==" 與equals方法的使用

 更新時間:2013年04月26日 18:02:12   作者:  
本篇文章介紹了,在java中"==" 與equals方法的使用。需要的朋友參考下
復(fù)制代碼 代碼如下:

public class equalsDemo {
     public static void main(String[] args){

         /*使用==來判斷兩個變量是否相等時,如果兩個變量時基本數(shù)據(jù)類型的
          變量時,且都是數(shù)值類型是,則只要兩個變量的值相等,使用==判斷就返回true*/

         int i=65;
         float f=65.0f;
         System.out.println(i==f);//true
         char c='A';
         System.out.println(c==f);//true
                 //但是對于兩個引用類型的變量,必須它們指向同一個對象時,==判斷才會返回true
         String str1=new String("hello");
         String str2=new String("hello");
         System.out.println(str1==str2);//false
         System.out.println(str1.equals(str2));//true
     }

 }

復(fù)制代碼 代碼如下:

public class IntegerDemo{
     public static void main(String[] args){
         Integer i1 =127;
         Integer i2 =127;
         System.out.println(i1==i2);//true
         Integer i3 =128;
         Integer i4 =128;
         System.out.println(i3==i4);//false
         //享元模式
     }

 }

相關(guān)文章

最新評論