Public Static voidMain (string[] args) {//StringString str = "string constant string constant"; String str1=NewString ("string constant");//Construction MethodString str2 =NewString ("string constant");//new open space for memoryString STR3 = "string Constant"; System.out.println ("Str=" +str); System.out.println ("Str1=" +str1); System.out.println ("Str2=" +str2); Char[]c=New Char[]{' Me ', ' very ', ' good '}; String STR4=NewString (c); System.out.println ("str4=" +STR4);
// The "= =" operation, which compares memory addresses for equality System.out.println ("STR1=STR2:" + (str1==str2)); System.out.println ("STR1=STR:" + (str1==str)); System.out.println ("STR=STR2:" + (str==str2)); System.out.println ("STR=STR3:" + (str==str3)); System.out.println ("STR1=STR2:" +str1.equals (str2)); System.out.println ("STR1=STR:" +str1.equals (str));
// String Information // string length System.out.println ("String length =" +str.length ()); // returns the index value of the first word after finding the position of the substring in the string, after going to the SYSTEM.OUT.PRINTLN ("Constant word Position:" +str.indexof ("constant")); System.out.println ("constant Position:" +str.indexof ("constant")); // not found, return value -1 System.out.println ("My Position:" +str.indexof ("I")); // returns the index value of the first word found from the position of the substring in the forward-looking string. System.out.println ("The position of the last constant word:" +str.lastindexof ("constant"));
// Get character Char C1=str.charat (4); System.out.println ("c1=" +c1);
Chapter 6, String (one)---initialization, string manipulation (29th,feb)