当前位置:网站首页>5. What is the difference between int and Integer?
5. What is the difference between int and Integer?
2022-08-03 06:10:00 【Shiyu】
One. Basic usage comparison
int is a basic data type, and the default value is 0 when used as a member variable.
Integer is a wrapper class for int. When used as a member variable, the default value is null.
int can be used directly without instantiation, and Integer can be used after instantiation.
int stores the value directly, while Integer is a reference to the object.
2. Compare size processing (using ==)
Usually compare the same numbers:
1. An int and an Integer:
int a=5;Integer b=5;a==b;//trueInteger objects are automatically unboxed and compared to int data.Return true.
2. Two new Integers: because they are both new objects, they are actually two different objects, not equal.Return false.
Integer a=new Integer(5);Integer b=new integer(5);a==b;//false3. One new and one not new: In fact, it is still a comparison of objects, and it should be that different objects are not equal.return false;
Integer a=5;Integer b=new Integer(5);a==b;//false4. Neither are new
The first case: the value is between -128-127, return true
Integer a=5;Integer b=5;a==b;//trueThe second case: the value is not between the above ranges, return false
Integer a=300;integer b=300;a==b;//falseReason: When the value is between -128-127, Integer a=5; it will be translated as Integer i = Integer.valueOf(5).The definition of valueOf of Integer type in the java API is as follows. For numbers between -128 and 127, it will be cached. When Integer a=5, 5 will be cached, and when Integer b=5 is written next time, it will be cached.It will be taken directly from the cache, and there will be no new.
边栏推荐
猜你喜欢

Kettle 从资源库中载入新的转换出错(Invalid byte 1 of 1-byte UTF-8 sequence)

【第四周】MobileNet和HybridSN

常见的电容器有哪些?唯样商城

深度学习基本概念

滚动条 scrollbar 和scrollbar-thumb 样式

电子元器件的分类有哪些?

自监督论文阅读笔记 Self-Supervised Deep Learning for Vehicle Detection in High-Resolution Satellite Imagery

芯片解密工作应该具备哪些条件?唯样商城

【第二周】卷积神经网络

MySql的Sql语句的练习(试试你能写出来几道呢)
随机推荐
double型数据转字符串后通过MCU串口发送
【第二周】卷积神经网络
Phase Vocoder的补充完善,Matlab音频变速不变调、变调不变速
classpath:与classpath*的比较
滚动条 scrollbar 和scrollbar-thumb 样式
自监督论文阅读笔记 DenseCL:Dense Contrastive Learning for Self-Supervised Visual Pre-Training
Qlik Sense 判空详解(IsNull)
动漫 吞噬星空
快速的将结构体各成员清零
ucosII OSMemCreate()函数的解析
最优化方法概述
自监督论文阅读笔记 Self-Supervised Visual Representation Learning with Semantic Grouping
[XSS, file upload, file inclusion]
block底层探索
servlet学习(七)ServletContext
【第一周】深度学习和pytorch基础
关于芯片你了解吗?
A.1#【内存管理】——1.1.3 page: struct page
自监督论文阅读笔记 TASK-RELATED SELF-SUPERVISED LEARNING FOR REMOTE SENSING IMAGE CHANGE DETECTION
IO 复用