PackageZhiZuo4; Public classTest { Public Static voidMain (string[] args) {//declaration Definition StringString A = "AAAAAA"; String B=NULL; B=NewString (); B=NewString ("AAAAA"); Char[] C =New Char[]{' A ', ' a ', ' a '}; String D=NewString (c); System.out.println ("String D length is" +d.length ()); System.out.println ("String D is" +D); //finding characters or strings intE = D.indexof ("AA"); System.out.println (E); intF = D.indexof ("B"); System.out.println (F); String G= "HDIASDKAENFKLAJKSJ"; intLa = G.lastindexof ("s")); System.out.println (LA); //To intercept a character or stringString H = g.substring (5); System.out.println (H); String J= G.substring (5, 6); System.out.println (J); //remove space before and afterString K = "Hu g T eyd"; System.out.println (K.trim ()); //Find ReplacementsSystem.out.println (K.replace ("", "")); String L= "Www,www, the money has been spent!" "; System.out.println (L.replacefirst ("WWW", "Poor Dead")); //judging the start and end of a stringSystem.out.println (L.startswith ("W")); System.out.println ((L.indexof ("W") ==0)); System.out.println (L.endswith ("! ")); //determine if strings are equalString A =NewString ("ABc"); String b=NewString ("ABc"); System.out.println ((A==b)); System.out.println ((a.equals (b))); //uppercase and lowercase conversionsSystem.out.println (A.touppercase ()); System.out.println (B.tolowercase ()); //String SegmentationString A2 = "A B c D E F"; String[] A3= A2.split (""); for(inti = 0;i<a3.length;i++) {System.out.print ("\ T" +A3[i]); } }}
Beginner java--Code Exercise (String)