1000 100 比较问题

来源:互联网 发布:飞狐交易师数据接口 编辑:程序博客网 时间:2024/04/29 00:00

//  正常情况应该是两个比较都是false  为什么 会100 会出现false呢  只是因为 jdk 会缓存 -127 128 之间的整数 这时的比较就是两个缓存的值得比较  



public static void main(String[] args) {

String d =tsetString();

System.out.println(d);  // true

String f =tsetString2(); //false

System.out.println(f);

}

public static String tsetString(){

               Integer a = 1000;

               Integer b = 1000;

               String c = " ";

               if(a==b){

               c = "true";

               }

               else{

               c = "false";

               }

               return c;

}

public static String tsetString2(){

        Integer a = 100;

        Integer b = 100;

        String c = " ";

        if(a==b){

        c = "true";

        }

        else{

        c = "false";

        }

        return c;

}

0 0