-
The number of characters contained in the string, that is, the length of the string
int length ();
-
Get a character from a position based on location
char charAt (int index);
-
Gets the character's position in the string according to the character
int indexOf (int ch) returns the position of the first occurrence of CH in the string.
int indexOf (int ch,int fromIndex) starts at the FromIndex specified position and gets the position where Ch appears in the string.
The int indexOf (string str) returns the position of the first occurrence of STR in the string.
The int indexOf (string str,int fromIndex) obtains the position of STR in the string, starting at the FromIndex specified position.
-
Whether a string contains a substring
Boolean contains (str)
-
Whether the string has content
Boolean IsEmpty ()
-
Whether the string starts with the specified content
Boolean StartsWith (str)
-
Whether the string ends with the specified content
Boolean EndsWith (str)
Example:
Public class stringdemo { public static void main (String[ ] args) { //String s1 = " Abidefghijkmln "; //method_1 (S1); //method_trans (); //method_replace (); method_split (); } Public static void method_split () { string s = "Zhansan,lisi,wangwu"; string[] names = s.split (","); for (String name:names)  {            SYSTEM.OUT.PRINTLN (name); } } public static void method_replace () { String s = "Wfjiwfsfhssfgha"; string new_s = s.replace (' F ', ' F '); sop (s); sop (new _s); } public static void method_trans () { char[] arr = {' A ', ' B ', ' C ', ' d ', ' e ', ' f ', ' G '}; string s = new string (arr,1,3); sop (s); } public Static void method_1 (string s) { sop ( S.length ()); sop (S.charat (5));//Occurs when a corner label does not exist in the accessed string stringindexoutofboundsexception sop (S.indexof (' I ', 6));//If not found, return to -1 } public static void sop ( object obj) { system.out.println (obj); }}
This article is from the "Azhome" blog, make sure to keep this source http://azhome.blog.51cto.com/9306775/1546370
Common operations for strings in Java learning Java