One.
public class Stringpool {
public static void Main (String args[])
{
String s0= "Hello";
String s1= "Hello";
String s2= "He" + "Llo";
System.out.println (S0==S1);//true
System.out.println (S0==S2);//true
System.out.println (New string ("Hello") ==new string ("Hello"));//false
}
}
Two.
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);
System.out.println (s1.equals (S2));
String s3= "Hello";
String s4= "Hello";
System.out.println (S3==S4);
System.out.println (S3.equals (S4));
}
Third, String Class of Length () , charAt () , GetChars () , replace () , toUpperCase () , toLowerCase () , Trim () , ToCharArray () instructions for use.
For:
1, String.Length () to find the length of the string, the return value is the length of the string.
2, String.charat () takes the character from a position in the string, starting with 0, for example string.charat (0) returns the first character of the string.
3, String.getchars () copies the characters in this string to the target character array.
4, String.Replace () replaces the element or substring in the original string. Returns the replaced string.
5. String.touppercase () capitalizes the characters in string strings.
6, String.tolowercase () to lowercase characters in string strings.
7, String.Trim () remove the string header space.
8, String.tochararray () converts a string to a character array.
Four, string encryption.
First, design ideas:
Define the class, the dialog reads into string s1, defines a char array of length (), CharAT () reads the character +3 in string (three bits backward), and stores (char) () in a char array. (Note Special cases "x" "Y" "Z")
Import javax.swing.*;
public class Jiami {
public static void Main (String[]args) {
String s1,s2= ""; int i;
S1=joptionpane.showinputdialog ("Input:");
Char a[]=new char[s1.length ()];
For (I=0;i<s1.length (); i++) {
if (S1.charat (i) = = ' x ')
A[i]= ' a ';
else if (S1.charat (i) = = ' Y ')
A[i]= ' B ';
else if (S1.charat (i) = = ' Z ')
A[i]= ' C ';
Else
A[i]= (char) (S1.charat (i) +3);
S2+=a[i]+ "";
}
Joptionpane.showmessagedialog (NULL,S2, "encrypted" +s1,joptionpane.closed_option);
}
}
Java Classroom Practice--string