文字列の一般的な操作

4513 ワード

 1 public class StringTest {

 2 

 3     public static void main(String[] args)

 4     {

 5         String a=new String("sSassasss");

 6         

 7         System.out.println(a.substring(1));

 8         

 9         System.out.println(a.substring(2,4));

10         

11         String[] array=a.split(",", 3);

12         System.out.println(array.length);

13         

14         System.out.println("Begin");

15         for(String str : array)

16             System.out.println(str+"
"); 17 System.out.println("End"); 18 19 String b=new String("ssss"); 20 21 //Compare that current string is equal to another. 22 if(a.equals(b)) 23 System.out.println("Equal"); 24 else 25 System.out.println("No Equal"); 26 27 //After ignore case,Judge that current string is equal to another. 28 if(a.equalsIgnoreCase(b)) //Ignore case. 29 System.out.println("Equal"); 30 else 31 System.out.println("No Equal"); 32 33 //Get special char position 34 System.out.println(a.indexOf("a")); 35 36 //Get special char position from third char on. 37 System.out.println(a.indexOf("a",3)); 38 39 } 40 }