常用API总结
Math
数字类,执行基本数字运算的
所有方法都是静态方法,直接使用类名.调用
| 方法名 | 说明 |
|---|---|
| public static int abs(int a) | 返回参数的绝对值 |
| public static double ceil(double a) | 向上取整 |
| public static double floor(double a) | 向下取整 |
| public static int round(float a) | 按照四舍五入返回最接近参数的int |
| public static int max(int a,int b) | 返回两个int值中的较大值 |
| public static int min(int a,int b) | 返回两个int值中的较小值 |
| public static double pow(double a,double b) | 返回a的b次幂的值 |
| public static double random() | 返回值为double的正值,[0.0,1.0) |
System
系统类,都是和系统相关的方法
所有方法都是静态方法,直接使用类名.调用
| 方法名 | 说明 |
|---|---|
| public static long currentTimeMillis() | 返回当前时间(以毫秒为单位) |
Object
所有类的祖类,为所有的子类提供一些公共的方法
一般直接使用子类对象调用方法
| 方法名 | 说明 |
|---|---|
| toString | 将对象转换成字符串展示。这个方法里实现规定了换成字符串的格式 |
| equals | 比较对象是否相等,默认比较地址值。重写可以比较内容 |
Objects
Object的工具类,为所有类提供一些公共的工具方法
所有方法都是静态方法,直接使用类名.调用
| 方法名 | 说明 |
|---|---|
| public static String toString(对象) | 返回参数中对象的字符串表示形式。 |
| public static String toString(对象, 默认字符串) | 返回对象的字符串表示形式。 如果对象为null,返回默认值 |
BigDecimal
可以进行精确的数学计算
new BigDecimal(String val);
| 构造方法 | 说明 |
|---|---|
| BigDecimal(String val) | 参数为String |
| 方法名 | 说明 |
|---|---|
| public BigDecimal add(另一个BigDecimal对象) | 加法 |
| public BigDecimal subtract (另一个BigDecimal对象) | 减法 |
| public BigDecimal multiply (另一个BigDecimal对象) | 乘法 |
| public BigDecimal divide (另一个BigDecimal对象,精确几位,舍入模式) | 除法 |
舍入模式:
BigDecimal.ROUND_Up进一法
BigDecimal.ROUND_FLOOR 去尾法
BigDecimal.ROUND_HALF_UP 四舍五入
Integer
为基本数据类型提供一些可以直接操作的方法
因为自动装箱的特点,直接使用即可
| 方法名 | 说明 |
|---|---|
| public static Integer valueOf(String s) | 将字符串转换成 Integer对象 |
| public static int parseInt(String s) | 将字符串转换成基本数据类型int |
| 方法名 | 说明 |
|---|---|
| public static String valueOf(int i) | 将int或者Integer转换成String |
Arrays
数组工具类,提供一些操作数组的方法
所有方法都是静态方法,直接使用类名.调用
| 方法名 | 说明 |
|---|---|
| public static String toString(int[] a) | 返回指定数组的内容的字符串表示形式 |
| public static void sort(int[] a) | 按照数字顺序排列指定的数组(快速排序) |
| public static int binarySearch(int[] a, int key) | 利用二分查找返回指定元素的索引 |
4308

被折叠的 条评论
为什么被折叠?



