由于String类具有多种方便功能,因此在此将介绍其使用方法。
2,程式碼
public class Main {
public static void main(String[] args) {
String name = "hiro";
boolean result = name.equals("hiro"); // true
int result = name.length(); // 4
char result = name.charAt(2); // r
int result = name.indexOf("h"); // 0
boolean result = name.isEmpty(); // false
String result = name.toUpperCase(); // HIRO
String result = name.toLowerCase(); // hiro
String result = name.trim(); // hiro
String result = name.replace("o", "a"); // hira
System.out.println(result);
}
}
Java教程