Java series Learning (12)-string, java series learning string
1. String Basics
Concept: A string is essentially an object for packaging character arrays. It isJava. lang. String class instance
2. String Constructor
public String()
public String(byte[] bytes)
public String(byte[] bytes, int offset, int length)
public String(char[] value)
public String(char[] value, int offset, int count)
public String(String original)
3. String features
(1) string constants and string pools
As long as the content is the same, no matter how many times the program code appears, JVM will only create a String instance and maintain it in the String pool.
[Note] the string written in "" is called a String constant.
(2) unchangeable string
Once a string is created, its content cannot be changed. The following code connects two strings with + and creates an object in practice.
4. Common Methods
4.1 convert a string to a basic type (the method in the basic type in the following method)
Byte.parseByte(String s)
Short.parseShort(String s)
Integer.parseInt(String s)
Long.parseLong(String s)
Float.parseFloat(String s)
Float.valueOf(String s)
Double.parseDouble(String s)
Double.valueOf(String s)
4. 2. String Functions
(1) Judgment Function
public boolean equals(Object anObject)
public boolean contentEquals(StringBuffer sb)
public boolean contains(CharSequence s)
public boolean startsWith(String prefix, int toffset)
public boolean endsWith(String suffix)
public boolean isEmpty()
(2) Retrieval
Public intLength()
Public charCharAt(Int index)
Public intIndexOf(String str)
Public intIndexOf(String str, int fromIndex)
Public intIndexOf(Int ch, int fromIndex )【ch-One character (Unicode code point )]
Public StringSubstring(Int beginIndex)
Public StringSubstring(Int beginIndex, int endIndex)
(3) Conversion Function
Public byte []GetBytes()
Public char []ToCharArray()
Public static StringValueOf(Char c) [A length is1String]
Public static StringValueOf(Int I)
Public StringToLowerCase()
Public StringToUpperCase()
Public StringConcat(String str) [connect the specified String to the end of this String]
(4) Other functions
A. Replacement Function
Public StringReplace(Char oldChar, char newChar)
Public StringReplace(CharSequence target, CharSequence replacement) [character set is a string]
B. Space Removal
Public StringTrim()
C. dictionary-based comparison
Public intCompareTo(String anotherString) [compare Unicode values based on each character in the String]
Public intCompareToIgnoreCase(String str)