==在对象、基本类型、Integer类中的使用

来源:互联网 发布:什么是bim软件 编辑:程序博客网 时间:2024/06/06 00:56
public class Test2 {    public static void main(String[] args) {        String str1=new String("hello");        String str2=new String("hello");        System.out.println(str1==str2?0:1);        String str3="hello";        String str4="hello";        System.out.println(str3==str4?0:1);        Integer a=127;        Integer b=127;        System.out.println(a==b?0:1);        Integer c=129;        Integer d=129;        System.out.println(c==d?0:1);    }}

结果为:1 0 0 1
注:Integer 类型的值在[-128,127] 期间,Integer 用 “==”是判断的为值;超出范围则为对象,按对象进行比较。

0 0
原创粉丝点击