当前位置:网站首页>Summary of common methods of string:
Summary of common methods of string:
2022-07-25 22:48:00 【Cool hair】
1. Use charAt() Method can get the character of the position of the index value corresponding to the string , Parameter is int String subscript of type , The return value type is char type .
2. Use compareTo() Method can compare the size of the current string with another string , Parameter is String String of type , The return value type is int type .
3. Use contains() Method can determine whether the current string contains a parameter string , The parameter is an interface type CharSequence, The return value type is boolean type . Return if present true, Returns if it does not exist false.
4. Use equals() Method to compare whether the contents of two strings are the same , Parameter is Object class , That is, you can pass any type of parameter , The return value type is boolean type , If the contents are equal, return true, Unequal return false.
5. Use equalsIgnoreCase() The method is to ignore case ( English letter ) Comparison , Parameter is String type , The return value is boolean type . After ignoring case , If the contents are equal, return true, Unequal return false.
6. Use startsWith() and endsWith() Method can determine whether the atomic character string starts or ends with the parameter string , Parameter is String type , The return value is boolean type , If it starts with a parameter string, it returns true, Otherwise return to false.
7. Use indexOf() Method can find the position where the parameter string first appears , The return value is int type , If it exists, the subscript position of the first occurrence of the string is returned , Otherwise return to -1.
8. Use lastIndexOf() Method can find the position of the last occurrence of the parameter string , The return value is int type , If it exists, it returns the subscript of the last occurrence of the string , Otherwise return to -1.
9. Use length() Method can get the length of the current string , The return value is int type .
10. Use replace() Method can replace string , The return value is String type .
11. Use split() Method to split a string , Parameter is String type , The return value is String[] Array
12. Use substring() Method intercepts the string , Parameter is int type , The return value is String type
13. Use toCharArray() Method converts the current string into an array of character types , The return value is char[] Type array
14. Use toLowerCase() or toUpperCase() Convert all letters to lowercase or uppercase , The return value is String type
15. Use trim() You can remove the first and last white space characters of the string , Include \t,\r,\n, The return value is String type
16. Use format() Format array output , Pass in the parameter , Replace placeholders , Generate a new string , The return value is String type
17. Use join() Method is used to splice strings , The return value is String type
18. Use valueOf() Method can convert any reference type or basic type to string type , The return value is String type
边栏推荐
猜你喜欢
随机推荐
Experiment 1, experiment 2 and Experiment 3 of assembly language and microcomputer principle: branch program design / loop program design / subroutine design
Box model (2)
【集训DAY15】Boring【树形DP】
为啥谷歌的内部工具不适合你?
Pyspark data analysis basis: pyspark.sql.sparksession class method explanation and operation + code display
Express framework
自媒体人必备的4个素材网站,再也不用担心找不到素材
Explore the use of self increasing and self decreasing operators
Short circuit effect of logical operators short circuit and short circuit or
Extended configuration of static routing in the second experiment
英文术语对应的解释
Simple setting of drop-down triangle
QT log file system
Multi data source switching
MySQL data type
Google analyzes how UA can be transferred to the latest version of GA4
Naming rules of software test pytest pytest the pre and post confitest of use cases Py customized allure report @pytest.mark.parameter() decorator as data-driven
What is the difference between bio, NiO and AIO?
【集训DAY15】油漆道路【最小生成树】
Severely crack down on illegal we media operators according to law: it is urgent to purify the we media industry









