day14总结

Object类的成员方法
重点
public int hashCode()

System.out.println(S2.hashCode());

public final Class getClass()

 System.out.println(S2.getClass().getName());

public String toString()

System.out.println(S2.toString());

在这里插入图片描述

public boolean equals(Object obj)

        System.out.println(s1.equals(s2)); 
        System.out.println(s1.equals(s1)); 
        System.out.println(s1.equals(s3)); //比较内容是否相同

protected void finalize()
protected Object clone()

  System.out.println(sClone.getName()+"---"+sClone.getAge());
public class demoStudent {
    public static void main(String[] args) {
        Student2 S2 = new Student2();
        System.out.println(S2.hashCode());
        System.out.println(S2.getClass().getName());
        System.out.println("***************************");
        System.out.println(S2.toString());
        System.out.println("***********");
        System.out.println(S2.getClass().getName()+"@"+Integer.toHexString(S2.hashCode()));//链式编程
    }
}

String类概述及其构造方法
String类概述
字符串是由多个字符组成的一串数据(字符序列)
字符串可以看成是字符数组
构造方法
public String()

String s = new String();

public String(byte[] bytes)

 String s1 = new String(b);//将一个字节数组转成一个字符串

public String(byte[] bytes,int offset,int length)

String s2 = new String(b, 1, 3);
 //将字节数组中的一部分截取出来变成一个字符串

public String(char[] value)

String s3 = new String(c);
//将一个字符数组转化成一个字符串

public String(char[] value,int offset,int count)

String s4 = new String(c, 4, 5);
//将字符数组中的一部分截取出来变成一个字符串

public String(String original)

String s6 =new String(s5);
//原始字符串

equals拼接

System.out.println(s3.equals(s1+s2)); //false


/通过System.identityHashCode(s3) 获取字符串的地址值
        System.out.println(System.identityHashCode(s3));

String类的获取功能:
重点 int length()

  //int length() 获取字符串的长度
        System.out.println(s.length());
            String substring(int start)
// 子字符串以指定索引处的字符开头,并扩展到该字符串的末尾。
        System.out.println(s.substring(3));
            String substring(int start,int end)
System.out.println(s.substring(4,6));
//获取下标4到6的元素

String类的判断功能
boolean equals(Object obj)

//boolean equals(Object obj) 比较字符串中的内容是否相同 区分大小写
        System.out.println(s1.equals(s2));
        boolean contains(String str)
//boolean contains(String str)
        //判断大的字符串中是否包含小的字符串,如果包含,返回的是true,否则就是false
        //区分大小写

        System.out.println(s1.contains("he"));
        boolean startsWith(String str)
   //boolean startsWith(String str)测试此字符串是否以指定的前缀开头。
        //区分大小写
        System.out.println(s1.startsWith("He"));
        boolean isEmpty()
 //boolean isEmpty()
 //判断是否为空
        System.out.println(s1.isEmpty());

String类的转换功能:
byte[] getBytes()

 //public byte[] getBytes()
        // 使用平台的默认字符集将此String编码为字节序列,将结果存储到新的字节数组中。
        byte[] b1 = s.getBytes();
        char[] toCharArray()
//char[] toCharArray()将此字符串转换为新的字符数组。
        //  字符串 ---> 字符数组
        char[] chars = s.toCharArray();
        static String valueOf(char[] chs)
 //字符数组 ----> 字符串
        static String valueOf(char[] chs)
        static String valueOf(int i)
/int类型的数据转化成字符串类型
        String s1 = String.valueOf(100)
        String concat(String str)
String s7 = s5.concat(s6);
//public String concat(String str)将指定的字符串连接到该字符串的末尾。
        //将小括号里面的字符串拼接到调用方法的字符串后面
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值