Java (3) common classes

@

Common Java classes

1、 String related classes

1. String class

public class StringTest { 
    String str = new String("good");
    char[] ch = { 't','e','s','t' };
    
    public void change(String str,char ch[]) {
        str = "test ok";
        ch[0] = 'b';
    } 
    
    public static void main(String[] args) {
        StringTest ex = new Stringtest();
        ex.change(ex.str,ex.ch);
        System.out.println(ex.str);
        System.out.println(ex.ch);
    }
}
/*
结果为
good
best
因为:
	1、传递给形参的都是引用数据类型,由值传递机制可知,把变量的地址传递给了形参。
	2、str的地址传递给形参:形参要改变数据内容,就需要另外开辟内存,但是没有影响到str
	3、数组的地址传递给形参:形参要改变数据内容,直接在上面操作,导致ch数据改变
*/

2. StringBuffer class

3. StringBuilder class

2、 Date time API before jdk8

1、java. Lang.system class

Returns the time difference between the current time and 0:0:0:0 on January 1, 1970, in milliseconds: public static long currenttimemillis()

2、java. util. Date class

3、java. text. Simpledateformat class

4、java. util. Calendar Class

3、 New date time API in jdk8

1、LocalDate、LocalTime、LocalDateTime

2. Instantaneous: instant

3. Formatting and parsing

4. Other APIs

4、 Java comparator

1. Explain

2. Natural sorting: examples of using the comparable interface

3. Custom sorting: comparator interface

4. Comparison between the two

5、 Other common classes

1. System class

2. Math class

3. BigInteger class

4. BigDecimal class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>