Arrays类
1.Arrays类提供了对数组操作的各种方法
2.常用方法
public static String toString(int[] arr);//把数组转换成字符串
public static void sort(int[] arr);//对数组进行升序排序
3.Arrays的构造方法是私有的。
私有构造方法是为了不让外界使用创建对象。
成员都用static修饰,可以用类名直接访问。
4.常用工具类的设计思想:(1)构造方法私有。(2)成员都用static修饰。
Math.pow(base, n);//base的n次幂 数学工具类
Collections:关系集合的一些操作方法
基本类型的包装类
1.为了对基本数据类型进行更多更方便的操作,java为每一种基本数据类型提供了一个对应的引用类型。
基本数据类型的包装类最常用的做法,就是做基本数据类型和字符串的相互转换。
基本类型 包装类
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
String–>char:
String s = “a”;
char c = s.charAt(0);
2.Integer类
构造方法:
Integer(int value);
Integer(String s);//s必须是数字字符串组成的,否则抛NumberFormatException
直接调用对象时,调用的是对象的toString()方法。toString()方法不重写,输出的是地址值。
把一个数字字符串转成一个包装类型,字符串里只能包含数字字符。
3.int与String类型的相互转换
Integer类的public int intValue();//Returns the value of this Integer as an int.
Integer类的public static Integer valueOf(String s);//Returns an Integer object holding the value of the specified String.
Integer类的public static Integer valueOf(int i);//Returns an Integer instance representing the specified int value.
Integer类的public static String toString(int i);//Returns a String object representing the specified integer.
Integer类的public static int parseInt(String s);//Parses the string argument as a signed decimal integer.
String类的public static String valueOf(int i);//Returns the string representation of the int argument.
int–>String:
方法一:int number = 100;
String s1 = “” + number;//比较方便,但不专业
方法二:String s2 = String.valueOf(number);
String–>int:
方法一:String–>Integer–>int
String s = “100”;
Integer i = new Integer(s);
int x = i.intValue();
方法二:int y = Integer.parseInt(s);
总结:
int–>String: String::public static String valueOf(int i);
String–>int: Integer::public static int parseInt(String s);