常用API

toString方法:返回调用对象的地址

//toS+回车 快捷重写toString方法
    @Override
    public String toString() {
        //return super.toString(); //返回地址                
        //重写后可以返回对象内容
        return name;  //返回调用对象的name
    }

equals方法:比较两者地址是否相同

@Override
public boolean equals(Object o) {
    //判断是否是同一个对象 是返回true
    if(this == o) return true;
    //如果o是null返回false 如果o不是学生类型返回false
    if(o == null || this.getClass()!=o.getClass()) return false;
    //说明o一定是学生类型且不为null
    Student student = (Student) o;
    return sex == student.sex && age == student.age && Object.equalse(name,student.name);
}

isNull方法:判断对象是否为null,null则返回true

System.out.println(Object.isNull(s1));  //s1为null输出true

 StringBuilder类:拼接、反转字符串

String:内容不可变,拼接字符串性能差    用于定义字符串

StringBuilder:内容可变,拼接字符串性能好,代码优雅    用于拼接字符串

//用StringBuilder拼接字符串
StringBuilder sb = new StringBuilder();
sb.append("123").append("456");
//最后还要恢复成String类型
String rs = sb.toString();
System.out.println(rs);

Math类:

public class Test {
    public static void main(String[] args) {
        //绝对值 abs
        System.out.println(Math.abs(-10)); //10
        //向上取整 ceil
        System.out.println(Math.ceil(4.0)); //4
        System.out.println(Math.ceil(4.000001));  //5
        //向下取整 floor
        System.out.println(Math.floor(4.9999999));  //4
        System.out.println(Math.floor(4.0));   //4
        //指数次方  pow
        System.out.println(Math.pow(2,3));  //2^3=8
        //四舍五入 round  由小数点后那一位决定
        System.out.println(Math.round(4.499999));  //4
        System.out.println(Math.round(4.500001));  //5
        //随机数 random
        System.out.println(Math.random()); //随机生成0.0-1.0的数
    }
}

 System类:功能通用,直接用类名调用,不能被实例化

    public static void main(String[] args) {
        System.exit(0);  //JVM终止  非0表示异常终止
        System.out.println(System.currentTimeMillis()); //返回当前系统时间的毫秒值形式  从1970.1.1开始
        int [] arr1 = {10,20,30,40,50,60,70};
        int [] arr2 = new int[6];  //[0,0,0,0,0,0] ==> [0,0,40,50,60,]
/*
        参数一:被拷贝的数组
        参数二:从哪个索引位置开始拷贝
        参数三:复制的目标数组
        参数四:粘贴位置
        参数五:拷贝元素的个数
*/
        System.arraycopy(arr1,3,arr2,2,3);
        System.out.println(Arrays.toString(arr2));

    }

BigDecimal:大数据类型,解决浮点型运算精度失真

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值