Math类的常用方法
| 方法名 | 说明 |
|---|
| public static int/double/float/long abs(int/double/float/long) | 返回参数的绝对值 |
| public static double ceil(double e) | 返回一个大于e的最小的整数 |
| public static double floor(double e) | 返回一个小于e的最小的整数 |
| public static int round(float e) | 按照四舍五入的规则返回一个整数 |
| public static double pow(int a,int b) | 返回a的b次幂的值 |
| public static double random() | 返回一个[0.0,1.0)的随机数。若要返回其他数值,可采用Random函数。 |
System类的常用方法
| 方法名 | 说明 |
|---|
| public static void exit(int status) | 终止当前运行的虚拟机(直接杀死程序),非零表示异常终止 |
| public static long currentTimeMillis() | 返回当前时间距1970年1月1日0:00时所过的毫秒数 |
Object类的常用方法
| 方法名 | 说明 |
|---|
| public String toString() | 返回对象的字符串表示形式 |
| public boolean equals(Object obj | 比较对象是否相等,默认比较地址,重写(自动生成)可比较内容。 |
Arrays类的常用方法
| 方法名 | 说明 |
|---|
| public static String toString(int[] a) | 返回指定数组的内容的字符串表达形式 |
| public static void sort(int[] a) | 按照数字升序排列指定的数组 |
基本类型包装类概述
将基本数据类型封装成对象的好处在于可以在对象中定义更多的功能方法操作该数据。
常用操作之一:用于基本数据类型(8个,无string,其为final修饰的java类)与字符串之间的转换。
| 基本数据类型 | 包装类 |
|---|
| byte | Byte |
| short | Short |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| char | Character |
| boolean | Boolean |
Integer类的常用方法
| 方法名 | 说明 |
|---|
| public static Integer valueOf(int i) | 返回指定的int值的Integer实例 |
| public static Integer valueOf(String s) | 将String类型转换成Integer类型,后使用intValue()方法转换成int类型 |
| public static int parseInt(String s) | 将String类型转换成int类型 |
String类的一个方法
public String[] split(String regex) 将一串字符根据regex间隔切割,存入数组中自动装箱和拆箱
装箱:把基本数据类型转换成对应的包装类类型。
拆箱:把包装类类型转换成对应的基本数据类型。
在使用包装类的时候,如果做操作,要先判断是否为null(否则容易出现空指针错误)。