1. 程式人生 > >String的幾種常用方法

String的幾種常用方法

public class Demo1 {
public static void main(String[] args) {
String stra = "Hello,World!";
String strb = new String("Hello,World!");
String strc = "Hello,World!";
System.out.println(stra.isEmpty());
System.out.println(stra.length());
System.out.println(stra.charAt(1));
System.out.println(stra.indexOf("d"));
//"equals"用來比較值是否相同,"=="用來對比所佔記憶體是否是同一塊記憶體
System.out.println(stra.equals(strb));
System.out.println(stra==strb);
System.out.println(stra.lastIndexOf("l"));
System.out.println(stra.replace("!","?"));
System.out.println(stra.equalsIgnoreCase(strb));
}

}