Math
| 方法名 方法名 | 说明 |
|---|---|
| public static int abs(int a) | 返回参数的绝对值 |
| public static double ceil(double a) | 返回大于或等于参数的最小double值,等于一个整数 |
| public static double floor(double a) | 返回小于或等于参数的最大double值,等于一个整数 |
| 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 void exit(int status) | 终止当前运行的 Java 虚拟机,非零表示异常终止 |
| public static long currentTimeMillis() | 返回当前时间(以毫秒为单位) |
Objects
| 方法名 | 说明 |
|---|---|
| public static String toString(对象) | 返回参数中对象的字符串表示形式。 |
| public static String toString(对象, 默认字符串) | 返回对象的字符串表示形式。 |
| public static Boolean isNull(对象) | 判断对象是否为空 |
| public static Boolean nonNull(对象) | 判断对象是否不为空 |
BigDecimal
进行精准计算
构造方法
| 方法名 | 说明 |
|---|---|
| BigDecimal(double val) | 参数为double |
| BigDecimal(String val) | 参数为String |
常用方法
| 方法名 | 说明 |
|---|---|
| public BigDecimal add(另一个BigDecimal对象) | 加法 |
| public BigDecimal subtract (另一个BigDecimal对象) | 减法 |
| public BigDecimal multiply (另一个BigDecimal对象) | 乘法 |
| public BigDecimal divide (另一个BigDecimal对象) | 除法 |
| public BigDecimal divide (另一个BigDecimal对象,精确几位,舍入模式) | 除法 |
包装类
| 基本数据类型 | 包装类 |
|---|---|
| byte | Byte |
| short | Short |
| int | Integer |
| long | Long |
| float | Float |
| double | Double |
| char | Character |
| boolean | Boolean |
Integer类
构造方法
| 方法名 | 说明 |
|---|---|
| public Integer(int value) | 根据 int 值创建 Integer 对象(过时) |
| public Integer(String s) | 根据 String 值创建 Integer 对象(过时) |
| public static Integer valueOf(int i) | 返回表示指定的 int 值的 Integer 实例 |
| public static Integer valueOf(String s) | 返回一个保存指定值的 Integer 对象 String |
自动装箱:把基本数据类型转换为对应的包装类类型
int → Integer
自动拆箱:把包装类类型转换为对应的基本数据类型
Integer → int
int和String互相转换
//int转换为String
class Test{
public static void main(String[] args){
//第一种方法,直接加一个空字符串
int num1 = 1;
String s1= num1 + "";
//第二种方法,public static String valueOf(int i)
String s2=String.valueOf(num1);
}
}
//===================================================
//String转换为int
class Test{
public static void main(String[] args){
String s = "100";
//方式一:先转换成Integer,再转成int
Integer i = Integer.valueOf(s);
int ii = i.intValue();
//方式二:通过Integer静态方法parseInt()
int a = Integer.parseInt(s);
}
}
Arrays
| 方法名 | 说明 |
|---|---|
| public static String toString(int[] a) | 返回指定数组的内容的字符串表示形式 |
| public static void sort(int[] a) | 按照数字顺序排列指定的数组 |
| public static int binarySearch(int[] a, int key) | 利用二分查找返回指定元素的索引 |
版权声明:本文为HWBclover原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。