数组常见操作、Arrays 类、基本数据类型包装类

1、基本数据类型包装类

● 将字符串转成基本数据类型

static Xxx parseXxx(String s),其中 Xxx 表示基本类型,此方法可将字符串转换成任意的基本类型,如果字符串无法转成基本类型,将会发生数字转换的问题 NumbeFormatException。

● Integer 类的静态成员变量

MAX_VALUE 和 MIN_VALUE

● Integer 类的静态方法

static String toBinaryString(int)十进制转二进制

static String toOctalString(int)十进制转八进制

static String toHexString(int)十进制转十六进制

● string ---- int 互转,按照指定的 radix 基数(进制)

static int parseInt(String s,int radix)

static String toString(int i,int radix)

● 自动装箱、拆箱之 Integer 特例:

 1     public static void main(String[] args) {
 2         Integer a1 = new Integer(127);
 3         Integer a2 = new Integer(127);
 4         
 5         Integer b1 = new Integer(128);
 6         Integer b2 = new Integer(128);
 7         
 8         System.out.println(a1 == a2);
 9         System.out.println(b1 == b2);
10         
11         //数据在byte范围内,jvm 不会重新 new 对象
12         Integer c1 = 127;//Integer c1 = new Integer(127);
13         Integer c2 = 127;//Integer c2 = c1;
14         
15         Integer d1 = 128;
16         Integer d2 = 128;
17         
18         System.out.println(c1 == c2);
19         System.out.println(d1 == d2);
20     }

● 结果:false、false || true、false

● 自动装箱、拆箱示例

1     public static void main(String[] args) {
2         Integer a = Integer.valueOf(10);//手动装箱
3         int b = a + 10;//自动拆箱
4     }

 

 

posted @ 2018-11-27 16:28  FanYiZhan  阅读(340)  评论(0编辑  收藏  举报