Java入门到精通(一)语言基础 包装类可以将基本数据类型的数据转换为对象进行处理。 Integer的构造函数 常见的常量有哪些? Double对象的构造函数 Character的构造函数 Math类常见的方法 java编译器以系统当前时间作为随机数生成器种子,因为每时每刻的时间不可能相同,所以生成的随机数将不同,但是如果运行速度太快,也会生成两次运行结果相同的随机数。 自动装包:把基本类型用它们对应的引用类型包装起来,使它们具有对象的特质,可以调用toString()、hashCode()、getClass()、equals()等方法。 编译器调用的是valueOf(int i)返回一个表示指定int值的Integer对象,如下: 以下是装包的源码: 两个Integer比较的时候,由于直接赋值的时候会进行自动的装箱,一个是-128<= 当赋值不在这个范围内,编译器直接创建对象,就是上述代码中的Integer b 与 Integer d作比较。 所谓拆包就是将引用类型转换为基本数据类型,编译器内部会调用int intValue()返回该Integer对象的int值。 自动装箱和拆箱是由编译器来完成的,编译器会在编译期根据语法决定是否进行装箱和拆箱动作。 描述不对的地方麻烦大佬补充
Java入门到精通(二)流程控制
Java入门到精通(三)数组介绍
Java入门到精通(四)字符串
Java入门到精通(五)面向对象
java入门到精通(六)面向对象知识拓展
讲给老年人听的异常处理
给大家安利一个jdk文档查看网站各种jdk版本文档都可以查看,我下面文章只提及常见的方法
jdk文档查看包装类
包装类及其对应的基本类型
包装类
对应的数据类型
Byte
byte
Integer
int
Float
float
Character
char
Short
short
Long
long
Double
double
Boolean
boolean
Integer类
Integer(int val) //Constructs a newly allocated Integer object that represents the specified int value. //传入一个int变量获取Integer对象 Integer(String str) //Constructs a newly allocated Integer object that represents the int value indicated by the String parameter. //传入一个String变量获取Integer对象,注意:字符串变量一定要是数值型否则编译器会抛出NumberFormatException。
方法
返回值
描述
valueOf(String str)
Integer
返回保存指定的String值的Integer对象
parseInt(String str)
int
返回包含在由str指定的字符串中的数字的等价整数值
toString()
String
返回一个表示该Integer值的String对象
equals(Object obj)
boolean
比较此对象与指定的对象是否相等
intValue()
int
以int型返回此Integer对象
compareTo(IntegeranotherInteger)
int
在数字上比较两个Integer对象、如果这两个值相等,则返回0;如果小于IntegeranotherInteger返回负值,反之返回正值
Integer 常量
MAX_VALUE = 2^31-1
MIN_VALUE = -2^31
SIZE 用来以二进制的形式来表示int值的位数
TYPE 表示基本类型int的Class实列Double类
Double(double value) //Constructs a newly allocated Double object that represents the primitive double argument. //传入double形式的参数创建Double对象 Double(String s) //Constructs a newly allocated Double object that represents the floating-point value of type double represented by the string. //传入String变量作为参数创建Double对象
方法
返回值
描述
valueOf(String str)
Double
返回保存指定的String值的Double对象
parseDouble(String str)
double
将String变量转换为Double返回一个Double值
doubleValue ()
double
以double形式返回Double对象
intValue()
int
将double转换为int型
compareTo(IntegeranotherInteger)
int
在数字上比较两个Integer对象、如果这两个值相等,则返回0;如果小于IntegeranotherInteger返回负值,反之返回正值
equals(Object obj)
boolean
比较此对象与指定的对象是否相等
toString()
String
返回一个表示该double值的String对象
Boolen类
Boolean(boolean value) //Allocates a Boolean object representing the value argument. //创建表示value参数的对象 Boolean(String s) //Allocates a Boolean object representing the value true if the string argument is not null and is equal, ignoring case, to the string "true". //以String变量作为参数创建对象
方法
返回值
描述
booleanValue()
boolean
将Boolean对象的值以对应的boolean值返回
equals(Object obj)
boolean
比较此对象与指定的对象是否相等并且值不为null
parseBoolean(String s)
boolean
将字符串转换为Boolean
toString()
String
返回一个表示该boolean值的String对象
valueOf(String s)
boolean
返回一个用指定字符串表示值的Boolean值
Character类
Character(char value) Constructs a newly allocated Character object that represents the specified char value. //将基本数据类型char转换为Character对象
方法
返回值
描述
compareTo(IntegeranotherInteger)
int
在数字上比较两个Integer对象、如果这两个值相等,则返回0
equals(Object obj)
boolean
比较此对象与指定的对象是否相等
toUpperCase(char ch)
char
将ch变为大写
toLowerCase(char ch)
char
将ch变为小写
toString()
String
返回一个表示该char值的String对象
charValue()
char
返回此Character对象的值
isDigit(char ch)
boolean
判断是否是数字
isLetter(char ch)
boolean
判断是否是字母
Math数学类
static double E //自然对数底数e的值 //The double value that is closer than any other to e, the base of the natural logarithms. static double PI //表示圆周率PI的值 //The double value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.
方法
介绍
sqrt(double a)
a的平方根
pow(double a,double b)
a的b次方
ceil(double a)
将a向上取整
floor(double a)
将a向下取整
max(double a,double b)
将a和b做比较返回最大值
min(double a,double b)
将a和b作比较返回最小值
abs(double a)
放回a的绝对值
random()
生成随机数
//random()方法 产生1~100的随机数切包括100 System.out.println(1 + Math.random()*100); System.out.println(Math.random()*101);
Random类
Random random = new Random(); int i = random.nextInt() * 100;//产生随机整数 float v = random.nextFloat()*100;//产生随机浮点数 boolean b = random.nextBoolean();//产生随机布尔值
拆装包
装包
Integer a = 10;//装包
Integer a = 10; => Integer a = Integer.valueOf(10);
Integer a = 100; Integer b = 200; Integer c = 100; Integer d = 200; Integer e = new Integer(10); Integer f = new Integer(10); System.out.println(a == b);//false System.out.println(a == c);//true System.out.println(b == d);//false System.out.println(e == f);//false System.out.println(b.equals(d));//true System.out.println(e.equals(f));//true
public static Integer valueOf(int i){ if(i>=IntegerCache.low && i<=IntegerCache.high){ return IntegerCache.cache[i+(-IntegerCache.low)]; } return new Integer(i); }
x<=127的整数,将会直接缓存在IntegerCache中,当赋值在这个区间的时候,不会创建新的Integer对象,而是从缓存中获取已经创建好的Integer对象。拆包
int a = new Integer(10);//拆箱
Integer a = 100; int b = 100; Integer c = 200; System.out.println(c > a);//true System.out.println(b == a);//true
看完感觉有用的点个赞,没有的也点个赞
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算