億陽信通的面試(一面)面試
String 底層是char[]數組數組
1.字符串截取spa
string.substring(int beginIndex)code
從索引位置截取直到結尾blog
String str="hello"; String str1=str.substring(1); system.out.println(str1);//ello
substring(beginIndex,endIndex)索引
String str="hello"; String str1=str.substring(1,4); system.out.println(str1);//ell
2.字符串查找字符串
indexOf("str")string
String str="hello"
int size=indexOf("s");//無這個值返回-1,
int size=indexOf("e");//返回下標1;由於String底層是char[]
3.字符串替換replace()class
String str="hello";
system.out.println(str.replace('e','a'));//hallo
4.字符串的長度di
String str="hello";
System.out.println(str.length());//5
5.判斷字符串是否相等
String str="hello"; String str2="hel"+"lo"; System.out.println(str.equals(str2));//true
equals()判斷字符串的值相等;==判斷字符串的存儲空間地址