Object:
equals(Object):boolean 判断两个对象是否"相等"
hashCode():int 返回对象的散列码
a.equals(b) ==> true, 则 a.hashCode() == b.hashCode() √
a.hashCode() == b.hashCode(),则 a.equals(b) ==> true ×
重写equals时一定要按照equals的比较规则去重写hashCode(Objects.hash(...))
toString():String 返回对象的字符串表示
getClass():Class 返回运行时对象的类型
wait():void 让当前线程等待,直到被唤醒
notify():void 唤醒等待的某个线程
notifyAll():void 唤醒等待的所有线程
protected finalize():void 析构方法,由 GC调用
protected clone():Object 克隆对象
需要让该类实现Cloneable接口,默认浅克隆
String:
public boolean equals(Object anObject): 将此字符串与指定对象进行内容比较
public boolean equalsIgnoreCase(String anotherString):将此字符串与指定对象进行内容比较,忽略大小写
public boolean contains(CharSequence s):当且仅当此字符串包含指定的char值序列时才返回true
public boolean startsWith(String prefix):测试此字符串是否以指定的前缀开头
public boolean endsWith(String suffix):测试此字符串是否以指定的后缀结尾
public boolean matches(String regx): 匹配是否满足参数的正则表达式
public boolean isEmpty():返回 true如果,说明长度为 0
public int compareTo(String anotherString):按字典顺序比较两个字符串,返回0表示一致,返回负数表示比参数字符串小,返回正数表示比参数字符串大
public int compareToIgnoreCase(String anotherString):按字典顺序忽略大小写比较
public int length():返回字符串对象的规范表示
public char charAt(int index):返回指定下标对应的字符
public int indexOf(String str):返回指定子字符串第一次出现的字符串中的索引
public int indexOf(String str, int fromIndex):返回指定子串的第一次出现的字符串中的索引,从指定的索引开始
public int lastIndexOf(String str):返回指定子字符串最后一次出现的字符串中的索引
public int lastIndexOf(String str, int fromIndex):返回指定子字符串的最后一次出现的字符串中的索引,从指定索引开始向后搜索
public String intern():返回字符串对象的规范表示
public byte[] getBytes():使用平台的默认字符集将此 String编码为字节数组返回
public byte[] getBytes(String charset):使用指定字符集将此 String编码为字节数组返回
public char[] toCharArray():将此字符串转换为新的字符数组
public String toLowerCase():将此字符串转换为全小写
public String toUpperCase():将此字符串转换为全大写
public String trim():返回该字符串去掉前后空格的新实例
public String[] split(String regex):将此字符串按照给定的regex(规则)拆分为字符串数组
public static String join(CharSequence delimiter, CharSequence... elements):返回一个新的字符串,由 elements的副本组成,并附有指定的delimiter分隔符
public String concat(String str):将指定的字符串连接到该字符串的末尾
public String substring(int fromIndex):从fromIndex开始截取字符串
public String substring(int fromIndex, int endIndex):从fromIndex-endIndex截取字符串,不包含endIndex
public String replace(CharSequence target, CharSequence replacement):将与target匹配的所有字符串替换为指定的replacement字符串,并返回替换后的副本
StringBuilder和StringBuffer
StringBuilder 非线程安全
StringBuffer 线程安全
包装类
基本 包装类
byte Byte
short Short
char Character
int Integer
long Long
float Float
double Double
boolean Boolean
包装类常用API:
Integer.parseInt(String):int 将字符串转为int
Integer.valueOf(int|String):Integer 将基本类型或字符串转换为包装类
包装类对象.intValue():int 将包装类拆箱成基本类型
BigDecimal类
解决浮点数精度问题:
BigDecimal num1 = new BigDecimal("2.0");
public BigDecimal add(BigDecimal augend): 加法运算
public BigDecimal subtract(BigDecimal subtrahend): 减法运算
public BigDecimal multiply(BigDecimal multiplicand): 乘法运算
public BigDecimal divide(BigDecimal divisor): 除法运算
public BigDecimal remainder(BigDecimal divisor): 模运算
public double doubleValue(): 将此 BigDecimal转换为 double
public BigDecimal round(MathContext mc):根据四舍五入的设置返回 BigDecimal
Math类
public int abs(int a):返回值为 int绝对值
public double ceil(double a):返回参数最大整数的double值
public double floor(double a):返回参数最小整数的double值
public int max(int a, int b):返回两个 int值中的较大值
public int min(int a, int b):返回两个 int值中的较小值
public double pow(double a, double b): 返回a的b次幂
public long round(double a):返回参数四舍五入后的值
public double random():返回大于等于 0.0,小于 1.0的浮点数