Package com.cloud.oop;
public class Demo2 {
/**
* @param args
*/
public static void Main (string[] args) {
System.out.println ("===string Type: Instantiate String class object = = =");
String name= "Tom";
System.out.println ("name=" +name);
String Name1=new string ("Cat");
System.out.println ("name1=" +name1);
System.out.println ("= = = = ' Compare string address = = =");
String str1= "Hello";
String Str2=new string ("Hello");
String str3=str2;
System.out.println (STR1==STR2);
System.out.println (STR1==STR3);
System.out.println (STR2==STR3);
System.out.println ("===equals comparison string content = = =");
System.out.println (Str1.equals (str2));
System.out.println (Str1.equals (STR3));
System.out.println (Str2.equals (STR3));
System.out.println ("= = = The contents of the string cannot be changed = = =");
/ /Here is the disconnect through the memory address, the connection realizes the change
String str4= "Hello";
str4=str4+ "China";
System.out.println (STR4);
System.out.println ("Common method of ===string class: tochararray===");
String strch= "Hello";
Char C[]=strch.tochararray ();
for (int i=0;i<c.length;i++) {
System.out.print (c[i]+ "\ t");
}
System.out.println ("");
String Strch1=new string (c);
String Strch2=new string (c, 0, 3);
System.out.println (strch1+ "\ n" +strch2);
System.out.println ("= = = takes a specified position from a string = = =");
String sptr= "Hello";
System.out.println (Sptr.charat (4));
System.out.println ("= = = and byte arrays convert = = = = = =");
String bystr= "Hello";
byte b[]=bystr.getbytes ();
System.out.println (New String (b));
System.out.println (New String (b,1,3));
System.out.println ("= = = Determine if the string exists = = = =)";
String instr= "Dsihsadhald";
System.out.println (Instr.indexof ("L"));
System.out.println (Instr.indexof ("D", 4));
SYSTEM.OUT.PRINTLN ("Query not returned:" +instr.indexof ("E"));
System.out.println ("= = = Remove whitespace on both sides of the string = = =");
String trstr= "Hell o";
System.out.println (Trstr.trim ());
System.out.println ("= = = Remove all spaces = = =");
String str7= "H e l o";
System.out.println (STR7);
String str8[]=str7.split ("");
for (int i=0;i<str8.length;i++) {
if (str8[i]== "") {
Return
}else{
System.out.print (Str8[i]);
}
}
}
}
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
Java Object-oriented: the use of the string class