(a) Please review the implementation Code of the String.Equals () method, and learn how to implement it. (Posted on blog assignments)
(ii) collating the Length (),charAt (), GetChars (),replace ( ), touppercase (), toLowerCase (),trim (),tochararray ( ) instructions for use
Length () : Get string length
String S1 = "Welcome to Java";
System.out.println ("s1 ' s length is:" + s1.length ());
Operation Result:
S1 ' s length is:15
charAt () : gets the character at the specified position
String S1 = "Welcome to Java";
System.out.println (S1.substring (4));
System.out.println (S1.substring (2, 7));
Operation Result:
Ome to Java
Lcome
GetChars () : gets the substring copied from the specified position into the character array (it has four parameters, as described in the example)
Char[] S1 = {' I ', ' ', ' l ', ' o ', ' V ', ' e ', ', ' h ', ' e ', ' R ', '! '};/ /s1=i Love her!
String s2 = new String ("you!"); S2.getchars (0,3,s1,7); S1=i Love you!
System.out.println (S1);
Running result: I love you!
replace () : substring substitution
String s = "Welcome to Java";
System.out.println (S.replace (' e ', ' m '));
System.out.println (S.replacefirst ("E", "AB"));
System.out.println ("Eleleledsafsdfhie". ReplaceAll ("El", "WML"));
Operation Result:
Wmlcomm to Java
Wablcome to Java
Wmlwmlwmledsafsdfhie
toUpperCase () , toLowerCase () : Uppercase and lowercase conversions
String s = "Welcome to Java";
System.out.println ("S.touppercase ():" +s.touppercase ()); S.touppercase (): WELCOME to JAVA
System.out.println ("S.tolowercase ():" +s.tolowercase ()); S.tolowercase (): Welcome to Java
Trim () : Remove the Kinsoku space:
String s = "Weer ewre";
System.out.println (S.trim ()); Weer ewre
ToCharArray () : Converts a String object to a character array
Char[] S1 = {' I ', ' ', ' l ', ' o ', ' V ', ' e ', ', ' h ', ' e ', ' R ', '! '};/ /s1=i Love her!
String s2 = new String ("you!"); S2.getchars (0,3,s1,7); S1=i Love you!
System.out.println (S1);
Operation Result:
I Love you!
(iii) String Encryption
Design Ideas : Use the Charat () function to get each character in a string, encrypt when all characters change the cost character to the last three bits of the character in the alphabet, but XYZ becomes ABC, and when decrypted all characters change the cost character to the first three digits of the alphabet, but ABC becomes XYZ.
Source code:
Results:
:
Java Job 4