本文共 1006 字,大约阅读时间需要 3 分钟。
publicclassExample8_20{publicstaticvoidmain(Stringargs[]){StringBufferstr=newStringBuffer();str.append("大家好");System.out.println("str:"+str);System.out.println("length...
public class Example8_20 {
public static void main(String args[]) {
StringBuffer str=new StringBuffer();
str.append("大家好");
System.out.println("str:"+str);
System.out.println("length:"+str.length());
System.out.println("capacity:"+str.capacity());
str.setCharAt(0 ,'w');
str.setCharAt(1 ,'e');
System.out.println(str);
str.insert(2, " are all");
System.out.println(str);
int index=str.indexOf("好");
str.replace(index,str.length()," right");
System.out.println(str);
}
}
import java.util.*;
public class Example8_12 {
public static void main(String args[]) {
String s="you are welcome(thank you),nice to meet you";
StringTokenizer fenxi=new StringTokenizer(s,"() ,");
int number=fenxi.countTokens();
while(fenxi.hasMoreTokens()) {
String str=fenxi.nextToken();
System.out.print(str+" ");
}
System.out.println("共有单词:"+number+"个");
}
}
展开
转载地址:http://llvqa.baihongyu.com/