Java高级---常用类

Java高级—常用类

一、object类

1.是所有对象的父类

2.getclass() 方法获取对象的类

3.hashcode()的哈希码,相同对象的哈希码一样

4.tostring()的重写,来返回有意义的变量值,而不是哈希码

public String toString(){

return name+age;

}

5.equals()重写–>两个对象的值是否相等

public boolean equals(Object obj){

​ if(this==obj) return true;

​ if(obj==null) return false;

​ if(obj instance of Student){//是否为当前类

​ Student s=obj;

​ if(this.name.equals(s.getname())&&this.age.equals(s.getage()))

​ return true;

​ }

}

6.finalize()方法:当对象被判定为垃圾对象,由JVM自动调用标记为垃圾对象,进入回收队列。

二、包装类

1.基本类型的数据存储在栈内,包装类型存储在堆里,是引用类型,默认值null

2.基本上是八个类型首字母大写:Byte,Boolean,Short,Integer,Double,Long,Character,Float

3.类型转换与装箱和拆箱 jdk1.8 自动装箱

基本–>引用 装箱 int num=10;Integer interger=num;

引用–>基本 拆箱 Integer interger=new Integer(100); int num=integer;

4.字符串和基本类型的转换

基本类型-》字符串 int n=100;String s1=Integer.tostring(n);

字符串-》基本类型 String str=“150”; int n=Integer.parseInt(str);

布尔类型转换时候 true转为 true,非true都是false

5.Integer缓冲区

在堆里面有缓冲区-128-127之间,装箱时候自动调用Integer.valueof,在缓冲区直接从堆里面取,超过则重新创建对象

①Integer i1=Integer.valueof(100); Integer i2=Integer.valueof(100);

i1==i2;

②Integer i1=Integer.valueof(200); Integer i2=Integer.valueof(200);

i1!=i2;

三、String类

1.字符串存储在字符串池中,在方法区中,可以共享

2.不可变性:在对字符串进行修改后,仅仅对字符串池中重新开辟空间然后改变指向

3.字符串比较用equals来比较内容,而不是地址

4.常用方法

length()长度

charat(int index)第index个字符

contains(String str)包含某个字符串吗

tochatarray()转成数组

indexof(String str)字符串首次出现的位置

lastindexof(String str)最后出现的位置

trim()去掉字符串首位的空格

touppercase()/tolowercase()转大小写

endwith(String str)/startwith(String str) 是否以str结尾/开始

replace(String str,String str)替换

split()分割后存在数组中[ ,]去除空格和逗号,[ ,]+去除多个空格和逗号

compareto()

四、StringBuffer和StringBuild

1.可变长字符串,build线程不安全,运行时间短

2.常用方法

append()

insert(index,str)

replace(start,end,str)

delete(start,end)

五、 BigDecimal类

1.double存储不精确,精确浮点数计算要用bigdecimal,而且要用字符串

六、Date类

1.常用方法

tostring() 返回年月日时分秒

gettime() 从1970.1.1开始的毫秒数

七、Calendar类

1.常用方法

静态的构造方法 ,只能getinstance() 创建对象,不能用new

gettimeinmillis() 获取毫秒值

get(Calendar.Year)获取时间

set(Calendar.Year,5)修改时间

add(Calendar.Year,5)修改时间

八、Simpledateformate类

1.format(Date) 格式化字符串,日期转为字符串

2.parse(yyyy/MM/dd) 字符串转为日期



图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值