Common methods Java strings

Java common methods of string

public static void main(String[] args) {

// TODO Auto-generated method stub

 

 

String aString = "hellocensi @gmail.com " ;

System.out.println(aString);

 

int lenthString=aString.length();

System.out.println ( "Way1 : " + lenthString); // common methods 1 : Get string length

 

char str [] = aString.toCharArray () ; // common method 2: is converted into character array

System.out.print("way2");

System.out.println(str);

for(int i=0;i<aString.length();i++)

System.out.print(str[i]+" ");

 

System.out.println ( "\ nway3 : " + aString.charAt (. 8)); // common method 3 : The subscript obtaining a single character

 

Of System.out.print ( "way4 : " + "\ n-"); // common method 4 : programming byte array

byte mybytes[]=aString.getBytes();

for(int i=0;i<mybytes.length;i++)

System.out.print(mybytes[i]+" ");

System.out.print("\n");

for(int i=0;i<mybytes.length;i++)

System.out.print ((char) mybytes [i ]); // byte converted to char

 

System.out.println ( "\ nway5:") ; // common method 5 : Find a single character

System.out.println(aString.indexOf('@'));

System.out.println (aString.indexOf ( '#') ); // not found return -1

 

String aString1 = "     hello jack";

System.out.println ( "way6:"); // common method 6 : Remove the space in front of the string

System.out.println(aString1);

System.out.println(aString1.trim());

 

   / * There are common methods are: 7. The interception of a substring from a string : subString ()

                  8. Case Conversion : the toLowerCase () , the toUpperCase ()

                  9. Analyzing the beginning and end of the character string : endsWith () , StartWith ()

                  10. Alternatively a character string : replace ()

                  ...

                  */

}

Like this article can follow me, I will continue to update, update your concerns are my motivation! For more java learning materials may also private letter I!

 

I wish my people are concerned about: good health, plenty of money, welfare, such as the East China Sea , many happy returns, Taoyuan County, from not afford to send !

Guess you like

Origin www.cnblogs.com/heqingxiaohuo/p/12350044.html