related knowledge points for String:
1.String Method of construction:
String () creates an empty content string object.
String (byte[] bytes) constructs a string object using a single byte array
String (byte[] bytes, int offset, int length)
Bytes: the array to decode
Offset: Specifies that the decoding is started from that index value in the array.
Length: To decode multiple elements.
String (char[] value) constructs a string using a character array.
String (char[] value, int offset, int count) uses a character array to construct a string, specifying the starting index value, and the number of characters to use.
String (int[] codepoints,int offset,int count)
String (string original)
Remember: You can construct a string object using either a byte array or a character array.
2. get the method
int length () Gets the length of the string
char charAt (int index) Gets the character at a specific position ( Corner label out of Bounds )
int indexOf (string str) finds the index value of the first occurrence of a substring and returns 1 if the substring does not appear in the string .
int lastIndexOf (string str) finds the last index value of the substring , and returns 1 if the substring does not appear in the string.
3 Judging Method
Whether Boolean endsWith (String str) ends with the specified character
Boolean isEmpty () If the length is 0 for example: "" null V1.6
Whether Boolean contains (charsequences) contains the specified sequence of applications: Search
Boolean equals (Object anobject) is equal
Boolean equalsignorecase (String anotherstring) ignores case equality
4 Conversion Method
Char[] ToCharArray () converts a string to a character array
Byte[] GetBytes ();
byte array and character array, string the three of them can be converted to each other.
5. Other methods
String Replace (string OldChar, String Newchar)
String[] Split (String regex) cut
String substring (int beginindex) Specifies the starting index value to intercept the substring
String substring (int beginindex, int endIndex) specifies the starting and ending index values to intercept the substring
String toUpperCase () to uppercase
String tolowercase () turns lowercase
String trim () to remove whitespace from the end of a string
6. String Features:
① strings are constants, and their values cannot be changed after they are created .
Once the contents of the ② string have changed, a new object is created immediately.
Note: The contents of the string are not suitable for frequent modification, as a new object is created as soon as the modification is made.
If you need to modify the contents of a string frequently, we recommend that you use a string buffer class (stringbuffer).
③StringBuffer is actually a container for storing characters.
If you need to modify the contents of a string frequently, we recommend that you use a string buffer class (stringbuffer).
StringBuffer of the relevant knowledge points
1.. StringBuffer is actually a container for storing characters.
① written question: What is the default initial capacity when creating an object using the StringBuffer parameterless constructor? How many times does it increase automatically if the length is not enough?
StringBuffer base is dependent on a character array to store character data, the default initial capacity of the string array , if the length of thecharacter array is not enough to use, automatically grow 1 times.
StringBuffer is a container for storing characters
② the behavior of the container
String
Increase
Append (Boolean B) can add any type of data to the container
Insert (int offset, Boolean b) specifies the index value to insert, inserting the corresponding content.
Delete
Delete (int start, int end) deletes the corresponding content based on the specified start and end index values.
Deletecharat (int index) deletes a character based on the specified index value.
Modify
Replace (int start, int end, String str) replaces the specified content with the specified start and end index values.
Reverse () flips the contents of the string buffer class. ABC--->CBA
Setcharat (int index, char ch) replaces the character of the specified index value with the specified character.
substring (int start, int end) intercepts substrings based on the specified index value.
ensurecapacity (int minimumcapacity) Specifies the length of the character array inside the StringBuffer.
View
IndexOf (string str, int fromIndex) finds the index value for the first occurrence of the specified string and specifies where to start the lookup.
LastIndexOf (String str)
Capacity () View the length of the current character array.
Length ()
charAt (int index)
ToString () turns the contents of the string buffer class back into a string.
the similarities and differences between StringBuffer and StringBuilder :
Same point:
1. Two classes are string buffer classes.
2. the methods of the two classes are consistent.
Different points:
1. StringBuffer is thread-safe , operating inefficient,StringBuilder is thread- insecure , High operating efficiency.
2. StringBuffer is jdk1.0 ,StringBuilder is jdk1.5 .
Recommended use: StringBuilder, because the operation of high efficiency.
related knowledge points of the Sytem class:
the system class is primarily used to obtain the system's property data.
common methods for 1.System classes :
Arraycopy (object src, int srcpos, object dest, int destpos, int length) General
SRC- source array.
Srcpos- The starting position in the source array.
Dest- target array.
Destpos- The starting position in the target data.
Length- The number of array elements to copy.
Currenttimemillis () Gets the current system system. Focus
Exit (int status) exits the JVM if the parameter is 0 to exit the JVM normally , not 0 indicates an exception exit JVM . General
GC () recommends that the JVM quickly start recycling garbage during garbage collection.
getenv (String name) Gets the environment variable based on the name of the environment variable.
GetProperty (Key)
Finalize () If an object is reclaimed by the garbage collector, the object's Finalize () method is called first .
Java Video Note--------String