[Java] package com. cxy. e; public class StringTest {www.2cto.com/*** String class */public static void main (String [] args) {// String. valueOf converts various types to String type int a = 123; String aStr = String. valueOf (a); System. out. println ("================================ "); // String Length String name = "chenxiaoyang"; System. out. println (name. length (); System. out. println ("================================ "); // String comparison String aa = new String ("cxy"); String bb = new String ("cxy"); String cc = "cxy"; String dd = "cxy "; if (aa. equals (bb) {System. out. println ("the value of aa and bb is the same");} if (aa = bb) {System. out. println ("reference of aa and bb is the same");} else {System. out. println ("references of aa and bb are different");} System. out. println ("================================ "); // String is case-insensitive. String aa1 = new String ("cxy"); String bb2 = new String ("Cxy"); if (aa1.equalsIgnoreCase (bb2) {System. out. println ("the values of aa and bb are the same (case-insensitive)");} if (aa1.equals (bb2) {System. out. println ("the value of aa and bb is the same (Case Insensitive)");} else {System. out. println ("the values of aa and bb are different (Case Insensitive)");} System. out. println ("================================ "); // compare the ratio of two strings: String aa2 = new String ("123"); String bb3 = new String ("1011"); if (aa2.compareTo (bb3) <0) {System. out. println ("aa2 before aa3");} else if (aa2.compareTo (bb3) = 0) {System. out. println ("aa2 and aa3 are equal");} else if (aa2.compareTo (bb3)> 0) {System. out. println ("aa2 following aa3");} System. out. println ("================================ "); // determine the start and end of the System. out. println ("hello world ". startsWith ("hello"); System. out. println ("hello world ". endsWith ("ld"); System. out. println ("================================ "); // search for the string System. out. println ("a, B, c, d, e, f ". indexOf (","); System. out. println ("a, B, c, d, e, f ". lastIndexOf (","); System. out. println ("a, B, c, d, e, f ". lastIndexOf ("@"); System. out. println ("================================ "); // string truncation System. out. println ("I like java api ". substring (7); System. out. println ("I like java api ". substring (7,11); System. out. println ("================================ "); // replace String tempTestStr = "I like java api"; System. out. println (tempTestStr. replace ("java", "c ++"); System. out. println (tempTestStr); System. out. println ("================================ "); // remove the leading and trailing spaces System. out. println ("I like java api ". trim (); System. out. println ("================================ "); // change the case sensitivity of System. out. println ("java api ". toUpperCase (); System. out. println ("java api ". toLowerCase (); System. out. println ("================================ "); // a very useful method String [] strArray = "a, bdfsgf, c, d, e, f ". split (","); for (String one: strArray) {System. out. println (one);} System. out. println ("================================ ");}}