** char charAt(int index) Returns the char value at the specified index. Char c = "中国 ". CharAt (1); // String is an object system.out.println (c); ** compareTo(String anotherString) // Compare two strings in dictionary order. int result = "abc".compareTo("abc"); System.out.println(result); Int result2 = "abcd". CompareTo ("abce"); System.out.println(result2); Result3 = -1 int result3 = "abce". CompareTo ("abcd"); // result3 = -1 int result3 = "abce". System.out.println(result3); System.out.println("xyz".compareto ("yxz"))); ** Boolean Contains (CharSequence s) // Check whether the preceding string contains the following substring System.out.println("HelloWorld.java".contains(".java")); ** Boolean endsWith(String suffix) // tests whether this String endsWith the specified suffix system.out.println ("text.txt".endswith (".java")); //false System.out.println("text.txt".endsWith(".txt")); // True **5.(master)** Boolean equals(Object anObject) // Compare this string with the specified Object. // Compare two strings using the equals method System.out.println("abc".equals("abc")); ** Boolean equalsIgnoreCase(String anotherString) // Check whether two strings are equal, Ignore case system.out.println ("ABC".equalsignorecase ("ABC")); Byte [] bytes = "abcdef".getBytes(); byte[] bytes = "abcdef".getbytes (); for (int i = 0; i < bytes.length; i++){ System.out.println(bytes[i]); } ** * int indexOf(String STR) // Returns the index at the first occurrence of the specified substring in the String System.out.println("oraclejavac++.netc#phppythonjavaoraclec++".indexOf("java")); String s = "a"; String s = "a"; String s = "a"; System.out.println(s.isEmpty()); ** int length(); // Return the length of the string. System.out.println(" ABC ".length()); ** int lastIndexOf(String STR) // returns the lastIndexOf the specified substring in this String System.out.println("oraclejavac++javac#phpjavapython".lastIndexOf("java")); ** Replace (CharSequence target, CharSequence replacement) // The parent interface of String is: CharSequence // Replace the contents of the String String newString = "http://ww.baidu.com". Replace ("http://","https://"); CharSequence // Replace the contents of the String String newString = "http://ww.baidu.com". System.out.println(newString); / / "=" replace ":" System. Out. The println (" name = zhangsan&password = 123 & age = 20 ". The replace (" = ", ":")); String[] ymd = "1980-10-11". Split ("-"); // Split with a "-" separator for (int I = 0; i < ymd.length; i++){ System.out.println(ymd[i]); } **14.(master)** Boolean startsWith(String prefix) // tests whether this String startsWith the specified prefix System.out.println("http://www.baidu.com".startsWith("http://")); //true **15.(master)** String subString (int beginIndex) // The parameter is a start index // cut a String System.out.println("http://www.baidu.com".substring(7)); //www.baidu.com **16. ** String substring(int beginIndex, int endIndex) // start index, endIndex System.out.println("http://www.baidu.com".substring(7, 10)); // WWW **17.(master)** char[] toCharArray() char[] toCharArray(); for (int i = 0; i < chars.length; i++){ System.out.println(chars[i]); } **18.(master)** String toLowerCase() // convert toLowerCase system.out.println ("ABCDefKXyz".tolowercase ()); ** String toUpperCase() // converts toUpperCase system.out.println ("ABCDefKXyz".touppercase ()); System.out.println(" hello world".trim()); ** Only one method in String is static and does not require a new object // This method is called valueOf // it converts "non-string" to "String" //String s1 = string.valueof (true); String s1 = String.valueOf(100); System.out.println(s1); Object obj = new Object(); // We can see from the source code: Why is toSring() called when a reference is printed // String.valueof() called when println is used, The string.valueof () method calls toString(). System.out.println() essentially converts any data to a String and then prints system.out.println (obj);Copy the code
`