簡單使用:
public class APITest {
public static void main(String[] args){
String name="Machin.echjidhu ";
System.out.println("字符串的長度爲:"+name.length());
System.out.println("字符串是否爲空:"+name.isEmpty());
System.out.println("下標爲5的字符是:"+name.charAt(5));
System.out.println("字符串是否爲 \"Machine\":"+name.equals("Machine"));
System.out.println("c字符第一次出現的下標是:"+name.indexOf('c'));
System.out.println("c字符第一次出現的下標是:"+name.lastIndexOf('c'));
System.out.println("字符串是否以\"Mac\"開頭"+name.startsWith("Mac"));
System.out.println("字符串是否爲hu結束"+name.endsWith("hu"));
System.out.println("字符是否包含:"+name.contains("ech"));
System.out.println("將字符串變成大寫:"+name.toUpperCase());
System.out.println("將字符串變成小寫:"+name.toLowerCase());
System.out.println("返回一個字符串:"+String.valueOf(89));
char[] oe = name.toCharArray();
System.out.print("字符串轉化爲字符數組後爲:");
for(int i=0;i<name.length();i++){
if(i!=name.length()-1){
System.out.print(oe[i]+",");
}
else{
System.out.print(oe[i]+"\n");
}
}
System.out.println("字符串中的ine用eni代替:"+name.replace("ine", "eni"));
String[] a=name.split("\\.");
System.out.println("字符串分割成.左右的字符串:"+a[0]+","+a[1]);
System.out.println("返回下標值4及後面的字符串"+name.substring(4));
System.out.println("返回下標值4後面(包括4)9前面(不包括9)的字符串"+name.substring(4,9));
System.out.println("去除首尾空格的字符串:"+name.trim());
}
}