java基础,Integer,String类型的 == 判断,以及++判断

代码

package test;

public class XIandeng {
	public static void main3(String[] args) {
		int c = 2;
		System.out.println(c);//2
		System.out.println(++c);//3
		System.out.println(c++);//3
		System.out.println(c);//4
	}
	public static void main(String[] args) {
		Integer i1 = 20;
		Integer i2 = new Integer(20);
		Integer i3 = 20;
		Integer i4 = 128;
		Integer i5 = new Integer(128);
		Integer i6 = 128;
		
		System.out.println(i1==i2);//false
		System.out.println(i1==i3);//ture
		System.out.println(i2==i3);//false
		System.out.println(i4==i5);//false
		System.out.println(i4==i6);//false
		System.out.println(i5==i6);//false
		
	}
	
	
	public static void main1(String[] args) {
		String s1 = "helloworld";
		String s2 = new String("helloworld");
		String s3 = "helloworld";
		String s4 = "hello"+"world";
		System.out.println(s1==s2);//false;
		System.out.println(s1==s3);//true;
		System.out.println(s1==s4);//true;
		System.out.println(s2==s3);//false;
		System.out.println(s2==s4);//false;
		System.out.println(s3==s4);//true;
		System.out.println(s1==s2.intern());//true;
	}
}

 

个人理解:

全部都是只有new对象,==,判断时一定不相等

1.Integer类型是int类型的包装类,当值在  -128  ------- 127 时不会new   Integer对象 超出这一个范围每一次都会new新的对象所以不会相等

2.String类型:每个string类型的值都会保存到常量池中,所以只要后面的String类型不是通过new产生对象的都会去常量池中找有没有该字符,如果有直接引用该字符串在堆中的地址值

 

3.++在前------>表示先加后用.

++在后--------->表示先用后加.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值