package cn. tedu. API;
import com. sun. org. apache. xalan. internal. xsltc. trax. XSLTCSource ;
import java. util. Arrays ;
public class TestString2 {
public static void main ( String [ ] args) {
String s = "abc" ;
char [ ] value = { 'a' , 'b' , 'c' } ;
String ss= new String ( value) ;
System . out. println ( s. charAt ( 1 ) ) ;
System . out. println ( s. concat ( "def" ) ) ;
System . out. println ( s) ;
String s2 = s. concat ( "ccc" ) ;
System . out. println ( s2) ;
System . out. println ( s. startsWith ( "a" ) ) ;
System . out. println ( s. endsWith ( "y" ) ) ;
System . out. println ( s. indexOf ( "b" ) ) ;
ss= "abcbb" ;
System . out. println ( ss. indexOf ( "b" ) ) ;
System . out. println ( ss. lastIndexOf ( "b" ) ) ;
System . out. println ( s== ss) ;
System . out. println ( s. equals ( ss) ) ;
System . out. println ( ss. length ( ) ) ;
String s3 = "a b c d e" ;
System . out. println ( Arrays . toString ( s3. split ( " " ) ) ) ;
String [ ] s33 = s3. split ( " " ) ;
for ( int i = 0 ; i < s33. length; i++ ) {
System . out. println ( s33[ i] ) ;
}
System . out. println ( ss. toUpperCase ( ) ) ;
System . out. println ( ss. toLowerCase ( ) ) ;
String s4 = "abcdefgh" ;
System . out. println ( s4. substring ( 3 ) ) ;
System . out. println ( s4. substring ( 1 , 5 ) ) ;
String s5 = " abcde " ;
System . out. println ( s5. trim ( ) ) ;
System . out. println ( String . valueOf ( 10 ) ) ;
System . out. println ( "20" + 10 ) ;
System . out. println ( String . valueOf ( 80 ) + 10 ) ;
}
}
String类的使用
package cn. tedu. API;
public class TestString {
public static void main ( String [ ] args) {
char [ ] value = { 'a' , 'b' , 'c' } ;
String s1 = new String ( value) ;
String s11 = new String ( value) ;
System . out. println ( s1) ;
String s2= "abc" ;
String s22= "abc" ;
String s3= "ccc" ;
System . out. println ( s1 == s2) ;
System . out. println ( s1 == s11) ;
System . out. println ( s2== s22) ;
System . out. println ( s2== s3) ;
System . out. println ( s1. equals ( s2) ) ;
System . out. println ( s1. equals ( s11) ) ;
System . out. println ( s2. equals ( s3) ) ;
}
}