public class Stringpool {
public static void Main (String args[])
{
String s1= "a";
String s2=s1;
System.out.println (S1==S2);//true
s1+= "B";
System.out.println (S1==S2);//false
SYSTEM.OUT.PRINTLN (s1== "AB");//false
System.out.println (s1.equals ("AB"));//true
}
}
Parsing: Assigning a value to a string means that two variables now refer to the same string variable object, so the S1==s2 return value of the True,string object is read-only, using + modifies the value of the S1 variable, actually getting a new string with the content AB, regardless of the object referenced by the original S1, So the return value is false, the string constant refers to a string that is not related to the object referenced by S1, and the String.equas () method can compare the contents of a two string.
public class Stringequals {
/**
* @param args the command line arguments
*/
public static void Main (string[] args) {
String S1=new string ("Hello");
String S2=new string ("Hello");
System.out.println (S1==S2);//Create two different objects with the new keyword, so the return value is False
System.out.println (s1.equals (S2));//content Same, value true
String s3= "Hello";
String s4= "Hello";
System.out.println (S3==S4);//content the same constant, referencing the same object, the return value is True
System.out.println (S3.equals (S4));//content Same, return value true
}
}
Length ()//returns the current string lengths
charAt (int index): takes one of the characters in a string, where the argument index refers to the ordinal number in the string. The ordinal number of the string is from 0 to length ()-1.
GetChars (int srcbegin,int srcend,char[]dst,int Dstbegin): This method copies a string to a character array. Where Srcbegin is the starting position of the copy, Srcend is the end position of the copy, the string array DST is the target character array, and Dstbegin is the starting position of the destination character array copy.
Replace (char Oldchar,char Newchar)//replaces the first Oldchar in a string with Newchar
toUpperCase ()://convert String to uppercase
toLowerCase ()://convert string to lowercase
Trim ()://Returns the string after the beginning and trailing spaces are removed
ToCharArray ()://Convert a String object to a char array
Hands-on brain (complement)