【JavaSE】3.常用API(一)String、StringBuilder、ArrayList



title: JavaSE_3.常用API(一)String、StringBuilder、ArrayList
date: 2020-10-16 20:01:08
tags: JavaSE

String String, StringBuilder

String class (immutable string object)

String a = new String(“hello”);

String a = "hello"; What is the difference between the two methods? Are they equals?

The result of x==y is true. It is because after the double quotes are assigned, x and y both point to the same memory address, and their references point to the same content in the method area, and the reference address is the same. When the same String literal value is created no matter what How many times, only one memory address is always allocated, and the following is a copy of this String, which is called "string resident" in Java. All string constants will automatically reside after compilation.
x = creation time "abcd" in this way will first see if the string pool already exists, there is direct return of the String object PermGen, otherwise it will create a new String object, after then put a string pool in

Methods of the String class:

length()
equals()
starsWith("")
endsWith(""subString(int beginIndex, int endIndex )
indexOf()
trim()

Note that the length here is only the method to find the length [length method];
equals is to see whether two Strings point to the same object;
subString returns a small array [intercept];
starsWith is mainly to see whether it starts with this [judgment] .
Trim is to clear the spaces on both sides [finish];

StringBuilder (variable string object)

Methods of StringBuilder:

append(String str)
insert(int offset, String str)
reverse()

append adds something to the end of the string; insert inserts a string of things in the middle; reverse is the method of seeking palindrome.

ArrayList collection class

Basic type of packaging: automatic boxing

Guess you like

Origin blog.csdn.net/weixin_43801418/article/details/110728587