String的常用方法和作用


1、
char[] value ={'a','b','c','d'};
String str = new String(value);//輸出 abcd
2、
char[] value ={'a','b','c','d'};
String str = new String(value, 1, 2);輸出 bc

3、

//獲取字符串的長度

 

 

 4、

 

 

  5、

 

 

  6、

 

 

  7、

 

   獲取字符在str中第一次出現的地方

 

  8、

String s = "helloworld";
// 從beginIndex開始截取字符串到字符串結尾
System.out.println(s.substring(0));//helloworld
System.out.println(s.substring(5));//world

   和

String s = "helloworld";
 // 從beginIndex到endIndex截取字符串。含beginIndex,不含endIndex。
System.out.println(s.substring(0, s.length()));//helloworld
System.out.println(s.substring(3,8));//lowor


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM