Java探秘之基本数据类型和包装类(int,Integer)(一)





Integer a = 34;
int b = 34;
Integer c = b;
int d = a;
System.out.println( a == b);
System.out.println( d == c);
Integer a = Integer.valueOf(34);
int d = a.intValue();
/**
* Returns an {@code Integer} instance representing the specified
* {@code int} value. If a new {@code Integer} instance is not
* required, this method should generally be used in preference to
* the constructor {@link #Integer(int)}, as this method is likely
* to yield significantly better space and time performance by
* caching frequently requested values.
*
* This method will always cache values in the range -128 to 127,
* inclusive, and may cache other values outside of this range.
*
* @param i an {@code int} value.
* @return an {@code Integer} instance representing {@code i}.
* @since 1.5
*/
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
public static void main(String[] var0) {
new User();
Integer var2 = Integer.valueOf(34);
byte var3 = 34;
Integer var4 = Integer.valueOf(var3);
int var5 = var2.intValue();
System.out.println(var2.intValue() == var3);
System.out.println(var5 == var4.intValue());
}
Integer a = 120;
Integer b = 120;
Integer c = 300;
Integer d = 300;
System.out.println( a == b);
System.out.println( d == c);






Integer b = Float.valueOf(a).intValue();
/**
* Returns the value of this {@code Float} as an {@code int} after
* a narrowing primitive conversion.
*
* @return the {@code float} value represented by this object
* converted to type {@code int}
* @jls 5.1.3 Narrowing Primitive Conversions
*/
public int intValue() {
return (int)value;
}
Long start = System.currentTimeMillis();
Long l = 0L;
for (Integer i = 0; i < Integer.MAX_VALUE; i++){
l++;
}
System.out.println(System.currentTimeMillis() - start);
Long start = System.currentTimeMillis();
long l = 0L;
for (int i = 0; i < Integer.MAX_VALUE; i++){
l++;
}
System.out.println(System.currentTimeMillis() - start);
到时候博客开通了,还需要各位老少爷们捧场哈。
作者: 小丑鱼yang
链接:http://www.imooc.com/article/17521
Java探秘之基本数据类型和包装类(int,Integer)(一)的更多相关文章
- Java面向对象 String 基本数据类型对象包装类
Java面向对象 String 知识概要: (1)String的用法详解 (2)基本数据类型对象包装类 String 顾名思义,该类主要是对字符串 ...
- 面试题:基础数据类型 包装类 int Integer
因为在学习集合时知道集合里存放的对象都是Object类型,取出的时候需要强制类型转换为目标类型(使用泛型集合不需要),如int a = (Integer)arrayList.get(0):然后我们就会 ...
- Java Number类(数据类型的包装类)
Java Number 一般地,当需要使用数字的时候,我们通常使用内置数据类型,如:byte.int.long.double等. 例如: int i = 5000; float gpa = 13.65 ...
- Java基础【基本数据类型包装类、int与String 之间的相互转换】
为什么会有基本类型包装类? 将基本类型数据类型封装成对象,这样的好处可以在对象中定义更多方法操作该数据. 包装类常用的操作就是用于基本数据类型与字符串之间的转换 问题:int a=100; 为什么不能 ...
- Java基础(34):Java中基本数据类型的包装类(主要为了不同数据类型之间更方便的进行转换)(Wrapper类)
相信各位小伙伴们对基本数据类型都非常熟悉,例如 int.float.double.boolean.char 等.基本数据类型是不具备对象的特性的,比如基本类型不能调用方法.功能简单...,为了让基本数 ...
- 黑马程序员——JAVA基础之基本数据类型包装类和1.5JDK新特性装箱
------- android培训.java培训.期待与您交流! ---------- 基本数据类型包装类: byte Byte short Short int Integer char Charac ...
- Java中基本数据类型和包装类
参考:深入剖析Java中的装箱和拆箱; Java中基本数据类型和包装类互转中 缓冲机制的使用; java学习笔记:装箱和拆箱,包装器和缓冲池 Java 各 类型数据在内存中分配情况详解 一 java内 ...
- java基本数据类型及其包装类
1.String类 String s1 = "hello world"; String s2 = "hello world"; String s3 = s1 + ...
- Java基础-数据类型和包装类
数据类型 分为基本数据类型和引用数据类型 基本数据类型变量存储的就是数据本身,引用数据类型的变量是保存数据的空间地址 四种基本数据类型: 逻辑型 boolean 文本型 char 整数型 byte s ...
随机推荐
- 深度解析PHP数组函数array_chunk
array_chunk是PHP中的一个数组分割函数,是将一个数组分割为多个数组块 我们可以把它理解卖豆腐的商人把一整块大豆腐切割为一个一个的小块来进行售卖 这个函数需要三个参数: 被切割的数组(必需) ...
- js常用的4种截取字符串方法
平常经常把这几个api的参数记混了,于是打算记录下来,当不确定的时候在拿出来翻翻: 在做项目的时候,经常会需要截取字符串,所以常用的方法有slice().substr().substring().ma ...
- Heartbeat高可用解决方案
Heartbeat高可用 Heartbeat作用: 通过heartbeat,可以将资源(ip以及程序服务等资源)从一台已经故障的计算机快速转移到另一台正常运转的机器上继续提供服务,一般称之为高可用服务 ...
- HTML表格表单综合——用户注册表
今天学习了表格和表单知识,我综合了他们添加了一些拓展知识做了一个用户注册表,以下面代码来整理表格和表单知识: <!DOCTYPE html PUBLIC "-//W3C//DTD XH ...
- blog界面自己写了css,参考了网站设计,想要的自己拿
junhey这就把界面的代码公布下来,可以自己修改额~(ps:麻烦加个友链http://www.cnblogs.com/junhey/ 谢谢) /* 初始化样式 */ html, body, div, ...
- android登录实现,存储数据到/data/data/包名/info.txt
1.一个简单登录界面布局代码如下: @1采用线性布局加相对布局方式 @2线性布局采用垂直排列 <?xml version="1.0" encoding="utf-8 ...
- AmpOne
AmpOne 基于Windows平台的Apache .PHP.Mysql 开发环境 | One intergrated tools package of Apache + PHP + MySQL fo ...
- react 基础
一.组件 函数式定义的无状态组件 es5原生方式React.createClass定义的组件 es6形式的extends React.Component定义的组件 React.Component是以E ...
- Java - byte[] 和 String互相转换
通过用例学习Java中的byte数组和String互相转换,这种转换可能在很多情况需要,比如IO操作,生成加密hash码等等. 除非觉得必要,否则不要将它们互相转换,他们分别代表了不同的数据,专门服务 ...
- Java线程池入门必备
线程池 一. 线程池的简介 1.什么是线程池? 最早期的工作线程处理任务的模型.一个任务的到来,会伴随着线程的创建,当处理完任务后,线程会被销毁,资源回收.这种一个任务一个线程一系列创建销毁的模式 ...