hands on Brain 1:
The result is:
Analysis:"=" Determines whether two objects are the same (stored address and stored content)
theequalsfunction determines whether the values of the two objects are equal
Length (),charAt (), getChars () of the String class, Replace (), touppercase () , tolowercase (),trim () ,tochararray () instructions for use:
1.string.length () is used to find the length of the string, and the return value is the length of the string.
Length ():p ublic int Length ()// Find string length
String s= "DWFSDFWFSADF";
System.out.println (S.length ());
2.string.charat () is a character that takes a position in the string, starting with 0 , for example, string.charat (0) returns the first character of the string.
CharAt ():p ublic charAt (int index)//index is a character subscript that returns the character at the specified position in the string
String s= "Hello";
System.out.println (S.charat (3));
3.string.getchars () copies the characters in this string to the target character array.
GetChars ():p ublic int getChars ()// copy character from this string to the target character array
String str= "Abcdefghikl";
Char[] Ch=new char[8];
Str.getchars (2,5,ch,0);
4.string.replace () replaces the element or substring in the original string. Returns the replaced string.
Replace ():p ublic int replace ()// Replace string
String s="\\\";
System.out.println(s.replace ("\\\","// "));
results ///;
5.string.touppercase () to capitalize the characters in string strings .
Touppecase ():p ublic string toUpperCase ()// convert all strings to uppercase
System.out.println (New String ("hello"). toUpperCase ());
6.string.tolowercase () changes the character in string to lowercase.
toLowerCase ():p ublic string toLowerCase ()// convert all strings to lowercase
System.out.println (New String ("HELLO"). toLowerCase ());
7.string.trim () is a space to remove the string's header.
Trim ():p ublic String trim ()
String x="ax C";
System.out.println (X.trim ());// is the way to go on both sides of the space
8.string.tochararray () converts a string to a character array.
ToCharArray (): String x="abcd";// converts characters in a string object to a single character array
Char Mychar[]=x.tochararray ();
System.out.println ("mychar[1]"+mychar[1]);
05 of the hands-on brain in Java