java复习---六七章

重写toString

当输出一个已重写toString方法的对象时(例如:System.out.println(ts);ts是一个实体类对象),输出代码会调用该对象的toString方法。即"System.out.println(ts);" = “ts.toString();”
如果没 重写直接sout(对象),会 输出 包名.test@14ae5a5
如果没写oString直接 SOUT(obj.toString)也是输出包名.test@14ae5a5

包名.test@14ae5a5 —Object类的toString方法被定义返回一个字符串,包含对象的类名和对象的地址值

equals

,系统默认的equals()方法比较的是地址而不是值

    test obj=new test(1,2);
        test obj2=new test(1,2);
        System.out.println(obj.toString());
        System.out.println(obj.equals(obj2));
    }

上面代码结果 是flase

包裹类

在这里插入图片描述

包裹类的目的

对于基本数据类型,Java提供了对应的包裹(wrap)类型。这些包裹类型将一个基本数据类型的数据转换成对象的形式,从而使得它们可以像对象一样参与运算和传递。

Boolean  wrapBool  = new Boolean("false");
Integer num1 = new Integer ("31");
Integer num2 = new Integer("3");
int sum = num1.intValue() * num2.intValue();

看看paseint

math类

abs…floar…

max,min

public class math {
    public static void main(String[] args) {
        int a=10;
        int b=20;
        System.out.println(Math.max(a,b));
    }
}

其他方法

public static double random()  产生一个01之间的随机数(不包括01)。
public static double pow(double a,double b) 返回a的b次幂。
public static double sqrt(double a)  返回a平方根。
public static double log(double a)  返回a的对数。
public static double sin(double a)  返回正弦值。
public static double asin(double a)  返回反正弦。
……

biginteger

string char

看蓝桥杯笔记

public class string {
    public static void main(String[] args) {
        char []arr =new char[]{'a','b','c'};
        String brr=new String(arr,0,1);
        System.out.println(brr);
    }
}

string的equals只要内容一样就行

    String crr="a";
        String drr="a";
        System.out.println(crr.equals(drr));

其他方法:

public boolean equals(String s) 比较当前字符串对象的实体是否与参数指定的字符串s的实体相同 
public int compareTo(String s)按字典序与参数s指定的字符串比较大小。
(3)判断
public boolean startsWith(String s)
public boolean endsWith(String s)
检索
public int indexOf (String s)
public int indexOf(String s ,int startpoint)
public int lastIndexOf (String s)5)子串
public String substring(int startpoint)
public String substring(int start ,int end)
public String trim()6)替换
public String  replaceAll(String old ,String new

字符串变成其他类型:paseint
其他变成字符串:valueof 没看

tochararrays:

  String t="abc";
        char []t2=t.toCharArray();
Stringbuffer

tring类字符串不能修改、删除或替换字符串中的某个字符
StringBuffer类能创建可修改的字符串序列
其他略

date
Date obj=new Date();  
System.out.println(obj.getDate()+"/"+obj.getMonth()+"/"+obj.getHours()+obj.getMinutes());
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值