尚学堂-常用类

1、String

java.lang.String代表不可变的字符序列

public class Test {
    public static void main(String[] args) {
        String s1 = "hello";
        String s2 = "world";
        String s3 = "hello";
        /*字符串常量存放在data segment,编译器往往对存放在data segment中
        的数据进行优化,当s1在data seg中分配一个"hello"了,当执行s3的时候
        不是重新再分配一个,而是直接指向已经存在的"hello",所以(s1 == s3)
        */
        System.out.println(s1 == s3); //true 

        s1 = new String("hello");
        s2 = new String("hello");
        System.out.println(s1 == s3); //false,s1和s2虽然内容一样,但不是同一个对象
        System.out.println(s1.equals(s3)); //true,查API文档,String重写了equals方法(见下图)

        char c[] = {'s', 'u', 'n', ' ', 'j', 'a', 'v', 'a'};
        String s4 = new String(c);
        String s5 = new String(c,4,4);
        System.out.println(s4);
        System.out.println(s5);
    }
}

String常用方法:

静态重载方法:

pubilc static String valueOf(...)可以将基本类型转换为字符串

public String[] split(String regex)可以将一个字符串按照指定的分隔符分隔,返回分隔后的字符串数组

StringBuffer

基础数据类型包装类

Math_and_File

递归列出目录结构

Enum

原文地址:https://www.cnblogs.com/wmjlh/p/7237086.html