Wu Yuxiong - natural born JAVA development of learning: String class

public class StringDemo{
   public static void main(String args[]){
      char[] helloArray = { 'r', 'u', 'n', 'o', 'o', 'b'};
      String helloString = new String(helloArray);  
      System.out.println( helloString );
   }
}
public  class StringDemo {
     public  static  void main (String args []) { 
        String Site = "www.runoob.com" ;
         int len = site.length (); 
        System.out.println ( "Tutorial novice URL length:" + len ); 
   } 
}
public  class StringDemo {
     public  static  void main (String args []) {      
        String string1 = "Tutorial novice URL:" ;      
        System.out.println ( ". 1," + string1 + "www.runoob.com" );   
    } 
}
System.out.printf ( "float variable value" + 
                  "% F, the value of the integer variable" + 
                  "% D, of the string variable value" + 
                  "% S IS", floatVar, IntVar, stringVar);
FS String; 
FS = String.format ( "float variable value" + 
                   "% F, the value of the integer variable" + 
                   "% D, of the string variable value" + 
                   "% S", floatVar, intVar, stringVar);
public class Test {
 
    public static void main(String args[]) {
        String s = "www.runoob.com";
        char result = s.charAt(8);
        System.out.println(result);
    }
}
public class Test {
 
    public static void main(String args[]) {
        String str1 = "Strings";
        String str2 = "Strings";
        String str3 = "Strings123";
 
        int result = str1.compareTo( str2 );
        System.out.println(result);
      
        result = str2.compareTo( str3 );
        System.out.println(result);
     
        result = str3.compareTo( str1 );
        System.out.println(result);
    }
}

public class Test {

    public static void main(String args[]) {
        String str1 = "STRINGS";
        String str2 = "Strings";
        String str3 = "Strings123";

        int result = str1.compareToIgnoreCase( str2 );
        System.out.println(result);
      
        result = str2.compareToIgnoreCase( str3 );
        System.out.println(result);
     
        result = str3.compareToIgnoreCase( str1 );
        System.out.println(result); 
    }
}

public class Test {
    public static void main(String args[]) {
        String s = "菜鸟教程:";
        s = s.concat("www.runoob.com");
        System.out.println(s);
    }
}
public class Test {
    public static void main(String args[]) {
        String str1 = "String1";
        String str2 = "String2";
        StringBuffer str3 = new StringBuffer( "String1");

        boolean  result = str1.contentEquals( str3 );
        System.out.println(result);
          
        result = str2.contentEquals( str3 );
        System.out.println(result);
    }
}

public  class the Test {
     public  static  void main (String args []) {
         char [] Strl = { 'H', 'E', 'L', 'L', 'O', '', 'R & lt', 'U ',' n-',' O ',' O ',' B ' }; 
        String Str2 in = "" ; 

        Str2 in = Str2.copyValueOf (Strl); 
        System.out.println ( "return result:" + Str2 in); 

        Str2 in Str2.copyValueOf = (Strl, 2,. 6 ); 
        System.out.println ( "return result:" + Str2 in); 
    } 
}
public  class the Test {
     public  static  void main (String args []) { 
        String Str = new new String ( "Novice Tutorial: www.runoob.com" );
         Boolean retVal; 
 
        retVal = Str.endsWith ( "runoob" ); 
        the System.out .println ( "return value =" + retVal); 
 
        retVal = Str.endsWith ( "COM" ); 
        System.out.println ( "return value =" + retVal); 
    }

public class Test {
    public static void main(String args[]) {
        String Str1 = new String("runoob");
        String Str2 = Str1;
        String Str3 = new String("runoob");
        boolean retVal;

        retVal = Str1.equals( Str2 );
        System.out.println("返回值 = " + retVal );

        retVal = Str1.equals( Str3 );
        System.out.println("返回值 = " + retVal );
    }
}
public class Test {
    public static void main(String args[]) {
        String Str1 = new String("runoob");
        String Str2 = Str1;
        String Str3 = new String("runoob");
        String Str4 = new String("RUNOOB");
        boolean retVal;

        retVal = Str1.equals( Str2 );
        System.out.println("返回值 = " + retVal );

        retVal = Str3.equals( Str4);
        System.out.println ( "return value =" + retVal); 

        retVal = Str1.equalsIgnoreCase (str4); 
        System.out.println ( "return value =" + retVal); 
    } 
}
import java.io.*;
 
public class Test {
    public static void main(String args[]) {
        String Str1 = new String("runoob");
 
        try{
            byte[] Str2 = Str1.getBytes();
            System.out.println("返回值:" + Str2 );
            
            Str2 = Str1.getBytes( "UTF-8" );
            System.out.println("返回值:" + Str2 );
            
            Str2 = Str1.getBytes( "ISO-8859-1" );
            System.out.println("返回值:" +Str2); 
        } the catch (UnsupportedEncodingException E) { 
            System.out.println ( "Unsupported character sets" ); 
        } 
    } 
}

public  class the Test {
     public  static  void main (String args []) { 
        String Strl = new new String ( "www.runoob.com" );
         char [] = Str2 in new new  char [. 6 ]; 

        the try { 
            Str1.getChars ( . 4, 10 , Str2 in, 0 ); 
            of System.out.print ( "copy string:" ); 
            System.out.println (Str2 in); 
        } the catch (exception EX) { 
            System.out.println ( "exception is triggered ... " ); 
        } 
    } 
}

public  class the Test {
     public  static  void main (String args []) { 
        String Str = new new String ( "www.runoob.com" ); 
        System.out.println ( "hash code string is:" + Str.hashCode ()); 
    } 
}

public class Main {
    public static void main(String args[]) {
        String string = "aaa456ac";  
        //查找指定字符是在字符串中的下标。在则返回所在字符串下标;不在则返回-1.  
        System.out.println(string.indexOf("b")); // indexOf(String str); 返回结果:-1,"b"不存在  
 
        // 从第四个字符位置开始往后继续查找,包含当前位置  
        System.out.println(string.indexOf("a",3));//indexOf(String str, int fromIndex); 返回结果:6  
 
        //(与之前的差别:上面的参数是 String 类型,下面的参数是 int 类型)参考数据:a-97,b-98,c-99  
 
        // 从头开始查找是否存在指定的字符  
        System.out.println(string.indexOf(99));//indexOf(int ch);返回结果:7  
        System.out.println(string.indexOf('c'));//indexOf(int ch);返回结果:7  
 
        //从fromIndex查找ch,这个是字符型变量,不是字符串。字符a对应的数字就是97。  
        System.out.println(string.indexOf(97,3));//indexOf(int ch, int fromIndex); 返回结果:6  
        System.out.println(string.indexOf('a',3));//indexOf(int ch, int fromIndex); 返回结果:6  
    }
}

public class Test {
    public static void main(String args[]) {
        String Str = new String("菜鸟教程:www.runoob.com");
        String SubStr1 = new String("runoob");
        String SubStr2 = new String("com");
 
        System.out.print("查找字符 o 第一次出现的位置 :" );
        System.out.println(Str.indexOf( 'o' ));
        System.out.print("从第14个位置查找字符 o 第一次出现的位置 :" );
        System.out.println(Str.indexOf( 'o', 14 ));
        System.out.print("子字符串 SubStr1 第一次出现的位置:" );
        System.out.println( Str.indexOf( SubStr1 ));
        System.out.print("从第十五个位置开始搜索子字符串 SubStr1 第一次出现的位置 :" );
        System.out.println( Str.indexOf( SubStr1, 15 ));
        System.out.print("子字符串 SubStr2 第一次出现的位置 :" );
        System.out.println(Str.indexOf( SubStr2 ));
    }
}

 

Guess you like

Origin www.cnblogs.com/tszr/p/10960245.html