The Get function of the string class: Packagecom.itheima_04;/** Get function of String class: * int Length (): Gets the length of the string, which is actually the number of characters * char charAt (int index): Gets the character at the specified index * int indexOf (String str): Get str The first occurrence of the index in a string object * string substring (int start): Intercepts the string from start * string substring (int start,int end): Starts from start and ends with the end of the intercept string. Includes start, not including end*/ Public classStringdemo { Public Static voidMain (string[] args) {//creating a String ObjectString s = "HelloWorld"; //int Length (): Gets the length of the string, which is actually the number of charactersSystem.out.println (S.length ()); System.out.println ("--------"); //char charAt (int index): Gets the character at the specified indexSystem.out.println (S.charat (0)); System.out.println (S.charat (1)); System.out.println ("--------"); //int indexOf (string str): Gets the index of the first occurrence of STR in a string objectSystem.out.println (S.indexof ("L")); System.out.println (S.indexof ("Owo")); System.out.println (S.indexof ("AK")); System.out.println ("--------"); //string substring (int start): Intercepts a string from startSystem.out.println (s.substring (0)); System.out.println (S.substring (5)); System.out.println ("--------"); //string substring (int start,int end): Intercepts a string from start to endSystem.out.println (s.substring (0, S.length ())); System.out.println (S.substring (3,8)); }}
The comparison between characters is ultimately a comparison of their corresponding integers in the ASCII code table.
String Class Fetch functionality