-
A string value is an object.
-
You cannot assign an initial value to a string variable with a variable of type char or char type.
-
Rectangle r = new Rectangle (x, y, width, height); where x and y indicate the coordinates of the upper-left corner of the rectangle, width and height indicate length and height.
-
A string class describing the string "hello" is no longer needed, and the memory address that holds the object is automatically reclaimed by Java, which can be used by other parts of the program. This mechanism is called garbage collection.
-
Final defines the constants of the base type, or you can define the object constants. When an object constant is defined, whether it is a string or any other type, only the reference to the object cannot be changed, that is, the constant is always associated with the same memory space.
-
Although an object constant must always be associated with a fixed memory, it does not mean that the contents of the memory cannot be changed by the member method.
Final Rectangle BLOCK = new Rectangle (6,9,4,2);
Block.setlocation (1,4);
Block.resize (8,3);
But the string itself is an object constant. The string class does not provide any way to alter an existing object.
-
String S1 = + "grams to a kilogram."; Grams to a kilogram.
String s2 = "Pi is less than" + 3.1416+ '. Pi is less than 3.1416.
String S1 = ' a ' + 3.14 + "!\n"; 100.14!\n
-
String Word; Word. length ();
-
The Member method is the means by which the Java object implements the behavior, and the class method is the service provided by the class.
-
String alphabet = "ABCDSFDSFdGkflieowergierogjerog";
Char C1 = alphabet. charAt (9);//9 is the subscript of the string, c1= ' d ';
String s2 = alphabet. substring (0, 6); The first argument, the starting position of the substring, the second argument, the end position of the substring +1.
String s3 = alphabet. substring (6); Start with the character Subscript 6 and the substring at the end.
String s4 = alphabet. trim (); Removes the first and trailing spaces of the source string and returns a new string.
int index = alphabet. indexOf ("Dgkflieo", 0); SUBSTRING matches. The first argument, the substring, and the second argument, the starting position of the lookup. Found, returns the starting position of the first occurrence of the substring; otherwise, returns-1.
/*
For each type, bool, char, int, long, float, and double, there is a valueof () class method. Takes only one parameter of the corresponding type and returns a reference to the new string. Converts the data for the type to the corresponding string.
*/
int v1 =-12;
string S1 = string. valueOf (v1); S1= "-12";
int v2 = alphabet. lastIndexOf ("G", Alphabet.length ()-1); The first argument, the substring, and the second argument, the position of the maximum lookup. Returns the maximum position that "G" is reached.
-