java.lang包中常用的类及其方法

JAVA API(图片来源:实验楼)

1098069-20170227191353157-5908517.png

包装类

Integer包装类
方法返回值功能描述
byteValue()byte以 byte 类型返回该 Integer 的值
intValue()int以 int 型返回此 Integer 对象
zebra stripesare neat以 int 型返回此 Integer 对象
toString()String返回一个表示该 Integer 值的 String 对象
valueOf(String str)Integer返回保存指定的 String 值的 Integer 对象
parseInt(String str)int返回包含在由 str 指定的字符串中的数字的等价数值

//十进制转成十六进制,返回值为String类型
Integer.toHexString(int i)
//十进制转成八进制
Integer.toOctalString(int i)
//十进制转成二进制
Integer.toBinaryString(int i)
//十六进制转成十进制
Integer.valueOf("FFFF",16)
//八进制转成十进制
Integer.valueOf("876",8)
//二进制转十进制
Integer.valueOf("0101",2)
//功能和Integer.valuesOf()一样
Integer.parseInt(String,radix);

String bb="1100";
String cc="1101";
int e=Integer.valueOf(bb,2);//功能一样
int ee=Integer.parseInt(cc, 2);
System.out.println(e);
System.out.println(ee);

String类

String类
方法返回值功能描述
indexOf(int ch)int搜索字符 ch 第一次出现的位置
indexOf(String value)int搜索字符串 value 第一次出现的位置
lastIndexOf(int ch)int搜索字符ch最后一次出现的位置
lastIndexOf(String value)int搜索字符串 value 最后一次出现的位置
substring(int index)String提取从位置索引开始到结束的字符串
substring(int beginindex, int endindex)String提取beginindex和endindex之间的字符串部分
trim()String返回一个前后不含任何空格的调用字符串的副本,意思是把字符串前后的空格部分去除

//字符串连接
concat();

StringBuffer类

StringBuffer 类是可变的。

方法返回值功能描述
insert(int offsetm,Object s)StringBuffer在 offetm 的位置插入字符串s
append(Object s)StringBuffer在字符串末尾追加字符串s
length()int确定 StringBuffer 对象的长度
setCharAt(int pos,char ch)void使用 ch 指定的新值设置 pos 指定的位置上的字符
toString()String转换为字符串形式
reverse()StringBuffer反转字符串
delete(int start, int end)StringBuffer删除调用对象中从 start 位置开始直到 end 指定的索引(end-1)位置的字符序列
replace(int start, int end, String s)StringBuffer使用一组字符替换另一组字符。将用替换字符串从 start 指定的位置开始替换,直到 end 指定的位置结束

Math类

方法返回值功能描述
sin(double numvalue)double计算角 numvalue 的正弦值
cos(double numvalue)double计算角 numvalue 的余弦值
acos(double numvalue)double计算 numvalue 的反余弦
asin(double numvalue)double计算 numvalue 的反正弦
atan(double numvalue)double计算 numvalue 的反正切
pow(double a, double b)double计算 a 的 b 次方
sqrt(double numvalue)double计算给定值的平方根
abs(int numvalue)int计算 int 类型值 numvalue 的绝对值,也接收 long、float 和 double 类型的参数
ceil(double numvalue)double返回大于等于 numvalue 的最小整数值
floor(double numvalue)double返回小于等于 numvalue 的最大整数值
max(int a, int b)int返回 int 型 a 和 b 中的较大值,也接收 long、float 和 double 类型的参数
min(int a, int b)int返回 a 和 b 中的较小值,也可接受 long、float 和 double 类型的参数
rint(double numvalue)double返回最接近 numvalue 的整数值
round(arg)arg 为 double 时返回 long,为 float 时返回 int返回最接近arg的整数值
random()double返回一个介于0与1之间的伪随机数

Class类

String obj=new String();
Class c;
c=obj.getClass();
System.out.println("String对象的类型是"+c.getName());;
c=Integer.class;
System.out.println("Integer对象的类型是"+c.getName());;
c=Class.forName("java.lang.String");
System.out.println("Character对象的类型是"+c.getName());;
c=c.getSuperclass();
System.out.println("Character对象的类型是"+c.getName());;
}

Object类

方法返回值功能描述
equals(Objectobj)boolean将当前对象实例与给定的对象进行比较,检查它们是否相等
finalize() throws Throwablevoid当垃圾回收器确定不存在对象的更多引用时,由对象的垃圾回收器调用此方法。通常被子类重写
getClass()Class返回当前对象的 Class 对象
toString()String返回此对象的字符串表示
wait() throws InterruptedExceptionvoid使当前线程进入等待状态

转载于:https://www.cnblogs.com/leungjj/p/6475945.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值