Math

1
2
3
4
5
6
7
8
9
10
public final class Math extends Object
{
public static final double E = 2.7182818284590452354; //常量
public static final double PI = 3.14159265358979323846;//π
public static double abs(double a) //求绝对值
public static double random() //返回一个0.0~1.0之间的随机数
public static double pow(double a, double b) //返回a的b次幂
public static double sqrt(double a) //返回a的平方根值
public static double sin(double a) //返回a的正弦值
}

String

1
2
3
4
5
6
7
8
9
10
11
12
public final class String extends Object implements java.io.Serializable, Comparable<String>,CharSequence
{
private final char value[]; //字符数组,最终变量
public String() //构造方法
public String(String original)
public String toString() //覆盖Object类中方法
public int length() //返回字符串的长度
public boolean equals(Object obj) //比较字符串是否相等
public boolean equalsIgnoreCase (String s)//忽略字母大小写
public int compareTo(String s) //比较字符串的大小
public int compareToIgnoreCase(String str)
}

Integer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public final class Integer extends Number implements Comparable<Integer>
{
public static final int MIN_VALUE=0x80000000;//最小值-231
public static final int MAX_VALUE = 0x7fffffff; //最大值231-1
private final int value; //私有最终变量,构造时赋值
public Integer(int value) //构造方法
public Integer(String s) throws NumberFormatException
public static int parseInt(String s) throws NumberFormatException //将字符串转换为整数,静态方法
public String toString() //覆盖Object类中方法
public static String toBinaryString(int i)//将i转换成二进制字符串,i≥时,省略高位0
public static String toOctalString(int i)//将i转换成八进制字符串,i≥时,省略高位0
public static String toHexString(int i)//将i转换成十六进制字符串
public boolean equals(Object obj)//覆盖Object类中方法
public int compareTo(Integer iobj)//比较两个对象值大小,返回1、0或1
}

Comparable

1
2
3
4
public interface Comparable<T>
{
int compareTo(T cobj) //比较对象大小
}

其中,是Comparable接口的参数,表示一个类。

举个栗子:MyDate类对象比较大小

1
2
3
4
5
6
7
8
9
10
11
public class MyDate implements Comparable<MyDate>
{
public int compareTo(MyDate d)//约定比较日期大小的规则,返回-1、0、1
{
if (this.year==d.year && this.month==d.month&& this.day==d.day)
return 0;
return (this.year>d.year || this.year==d.year &&
this.month>d.month || this.year==d.year &&
this.month==d.month && this.day>d.day) ? 1 : -1;
}
}