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