String class
PackageDay6;Importjava.util.Arrays; Public classStringtest { Public Static voidMain (string[] args) {//= = Compares the size of a two data//The storage area of the base data type is in the stack, and each data is independent of each other. inti = 5; intj = 5; System.out.println (i==j); //arrays are reference data types,//arrays occupy two blocks: stacks and heaps//The first address (array name) in the stack where the array data resides in the heap//array data is stored in the heap intArr1[] =New int[2]; arr1[0] = 1; arr1[1] = 2; intArr2[] =New int[2]; arr2[0] = 1; arr2[1] = 2; System.out.println (arr1==arr2); System.out.println (Arrays.equals (arr1, arr2)); //The ordinary method of declaring a string will only open up space in the string constant pool;//and before it is opened, it checks whether the string constant pool exists;//the same data, if any, points directly to the existing data, and if not, opens up a new space in the string constant pool;String s = "Ccy"; String S2= "Ccy"; System.out.println (S==S2); //Create a space in the heap, store the content, and then check the string constant in the pool without having to open up a space in the pool to store JerehString s3 =NewString ("Jereh"); String S4=NewString ("Jereh"); System.out.println (S3==S4); String S6=NewString ("jredu"); String S5= "Jredu"; System.out.println (S5==S6); }}
=============================================================================================================== ===
Package Day6; Public class Demo03 { //. Concat () link string public staticvoid Main (string[] args) { new String ("Nihao"); New String ("Zhangsan"); = String.Concat (name); SYSTEM.OUT.PRINTLN (ABC);} }
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
PackageDay6;ImportOrg.omg.CORBA.INTERNAL;ImportDay52.shuzu; Public classDemo04 { Public Static voidMain (string[] args) {String a=NewString ("Asdf.java"); //indexOf () gets where a character or string in a string appearsSystem.out.println (A.indexof ("a")); //lastindesof () Gets the position of the last occurrence of a character or string in a stringSystem.out.println (A.lastindexof ("a")); //substring (index) intercepts the string starting at the specified position (inclusive), knowing that the lastString Newa = a.substring (4); System.out.println (Newa); intindex = A.indexof (".")); String newA2= A.substring (index+1); System.out.println (newA2); //starts (contains) from the specified index and ends at the specified index (not included)String newA3 = a.substring (2,4); System.out.println (newA3); //trim () go back and forth spaceString s2 = "Jerry Education"; String newS4=S2.trim (); System.out.println (NEWS4); } }
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
PackageDay6; Public classDemo06 { Public Static voidMain (string[] args) {//DelimitedString words = "changting outside the ancient road side of the grass green night breeze blowing Liudisheng sound remnant Sunset Mountain outside the mountain"; String[] Printword=Newstring[100]; System.out.println ("* * * Original lyrics format ***\n" +words); System.out.println ("\n*** lyrics format after splitting"); Printword= Words.split (""); for(inti = 0; i < printword.length; i++) {System.out.println (printword[i]); } }}
¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
PackageDay6; Public classDemo07 { Public Static voidMain (string[] args) {//StringBuffer//append () to append content to StringBuffer.StringBuffer SB =NewStringBuffer ("Qwer"); intnum = 110; StringBuffer SB1= Sb.append ("qwerty"); System.out.println (SB1); StringBuffer SB2= Sb1.append ("qwerty"); System.out.println (SB2); StringBuffer SB3=sb2.append (num); System.out.println (SB3); //String---> StringBufferStringBuffer s =NewStringBuffer ("Qwer"); //stringbuffer---> Stringsb.tostring (); }}
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
PackageDay6;ImportJava.util.Scanner; Public classDemo08 { Public Static voidMain (string[] args) {//stringbuffer Insert (indexed index, method content) methodScanner Scanner =NewScanner (system.in); System.out.println ("Qingshuru"); String String=Scanner.next (); StringBuffer Buffer=NewStringBuffer (string); for(inti = Buffer.length ()-3; i > 0; I-=3) {Buffer.insert (I,","); } System.out.println (buffer); Scanner.close (); }}
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Package Day6; Import java.util.Arrays; Public class Test { publicstaticvoid main (string[] args) { = "Love You, Love Me, love her." , Love China! Love "; = "+string+" "; int length = String.Split ("Love"). Length-1; System.out.println (length); }}
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Packageday61; Public classTest {//global variable has an initial value//local variable has no initial value inti; //or under the int i = 0; Public voidCheck () {//int i =0;System.out.println (i); } Public Static voidMain (string[] args) {test test=NewTest (); Test.check (); }}
Java's Day6