[Java 教學範例拷貝]- String 類別(2/3)
[Java 教學範例拷貝]- String 類別(2/3)
剛才找資料時發現一個的Java 教學網站,趕快發揮(C/P)的長才將它備份來,有需要的同好,歡迎來(C/P)一下^^。
拷貝來源:
http://openhome.cc/Gossip/JavaGossip-V1/
http://openhome.cc/Gossip/JavaGossip-V1/StringClass.htm
public class UseString {
public static void main(String[] args) {
String text = "Your left brain has nothing right.\n"
+ "Your right brain has nothing left.\n";
System.out.println("字串內容: ");
for(int i = 0; i < text.length(); i++)
System.out.print(text.charAt(i));
System.out.println("\n第一個left: " +
text.indexOf("left"));
System.out.println("最後一個left: " +
text.lastIndexOf("left"));
char[] charArr = text.toCharArray();
System.out.println("\n字元Array內容: ");
for(int i = 0; i < charArr.length; i++)
System.out.print(charArr[i]);
}
}
|