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
原文地址:https://www.cnblogs.com/zhaohuihui/p/12160345.html