117. What are the methods of String

1.charAt() returns the character at the specified index.

	String s="1234567890";
	char t=s.charAt(9);
	System.out.println(t);
    //输出t=0

2.equals compares whether two strings are exactly the same (content + address)

3.equalsIgnoreCase does not consider case comparison

4.getBytes() method has two forms

getBytes(String charsetName): Use the specified character set to encode the string into a byte sequence, and store the result in a new byte array.

getBytes(): Use the platform's default character set to encode the string into a byte sequence, and store the result in a new byte array.

5.length() string length

6. getchars() intercepts multiple characters and receives them by other strings

7. toCharArray() turns a string into a character array

8. startsWith() and endsWith() determine whether the string starts or ends with a specific character

9. toUpperCase() and toLowerCase() convert the string to uppercase or lowercase

10. concat() connect two strings

11. trim() to remove the starting and ending spaces

12. substring() intercepts the string

13. IndexOf() and lastIndexOf() The former is to find the first occurrence of a character or string, and the latter is to find the last occurrence of a character or string

14. replace() Replace

15. compareTo() and compareToIgnoreCase() compare the size of two strings in lexicographical order, the former is case sensitive, the latter is not

Guess you like

Origin blog.csdn.net/weixin_43206161/article/details/112324607