JavaSe笔记3.21

  1. 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接口,默认浅克隆

  1. 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字符串,并返回替换后的副本

  1. StringBuilder和StringBuffer

StringBuilder 非线程安全

StringBuffer 线程安全

  1. 包装类

基本 包装类

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 将包装类拆箱成基本类型

  1. 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

  1. 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的浮点数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值