The string is a special object
Once the string is initialized, it cannot be changed.
Gets the length of the string
Call the length () method of the String object to return int lengths
Gets the character of an index position
Call the charAt () method of the String object to get the char character, parameter:int Index of type
Gets the index position in the string based on the character
Call the indexOf () method of the String object to get the first occurrence of the int index position, return -1 Just doesn't exist, argument: String Type
Gets the substring, according to the index
Call the substring () method of the String object , Parameter:typeint to start index
Determine if a string has content
Call the IsEmpty () method of the String object to get the Boolean value
Determine if the string contains another string
Call the contains () method of the string object to get the Boolean value, Parameter:string object
Converting basic data types into strings
Call string.valueof (), Parameters: base data type
Convert a string into a character array
Call the ToCharArray () method of the String object to get the byte array
Converting a string into a byte array
Call the getBytes () method of the String object to get the byte[] byte array
Converts a string to a string array, followed by the specified character
Call the split () method of the string object , parameter:string
Replace string
Call the replace () method of the string object , parameter: old string, new string
Public classStringdemo {/** * @paramargs*/ Public Static voidMain (string[] args) {String name= "Taoshihan Taoshan"; System.out.println (Name.length ());//OutputSystem.out.println (Name.charat (9));//Output PotterySystem.out.println (Name.indexof ("Tao"));//Output 9System.out.println (name.substring (9));//Output TaoshanSystem.out.println (Name.contains ("Shi"));//Output TrueSystem.out.println (string.valueof (1));//Output 1System.out.println (Name.tochararray ());//Output Taoshihan TaoshanSystem.out.println (Name.getbytes ());//output [[email protected]System.out.println (Name.split ("n"));//Output [Ljava.lang.string;@77a477b7System.out.println (Name.replace ("Han", "Han"));//output Taoshi Culvert Taoshan }}
PHP version, full correspondence
<?PHP$str= "Taoshihan Taoshan";EchoMb_strlen ($str, "Utf-8");//OutputEcho $str{8};//output N; This method is garbled in Chinese, there is no similar charat () method in PHPEcho Strpos($str, "Tao");//Output 9EchoMB_SUBSTR ($str, 9);//Output TaoshanEcho strstr($str, "Shi");//Output Shihan TaoshanEcho(string) 1;//output 1//php No string to character array self-band method//php no string to byte array self-band methodPrint_r(Explode("N",$str));//output Array ([0] = Taoshiha [1] = Taoshan)Echo Str_replace("Han", "Han",$str);//output Taoshi Culvert Taoshan
[Javase] Basic type (string dependent)