class Stringtest
{
public static void main(String[] args)
{ // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// String
// 截取
// .charAt
char ch;
ch="abc".charAt(2);
System.out.println(ch);
// .getChars
String s="This is a demo of the getChars method. ";
int start=10;
int end=14;
char buf[]=new char[end-start];
s.getChars(start,end,buf,0);
System.out.println(buf);
// .getBytes --用法不清楚
System.out.println(s.getBytes());
// .toCharArray -- 把字符串转成字符数组
char tochararray[]=s.toCharArray();
System.out.println(tochararray[3]);
// 比较
// .equals
// .equalsIgnoreCase 忽略大小写
// .regionMatches 比较指定区间的字符串,重载形式可以忽略大小写
// .startsWith 是否以指定的字符串开始
// .endsWith 是否以指定的字符串结束
// .compareTo
// .compareToIgnoreCase
// 搜索
// .indexOf 首次出现
// .lastIndesOf 最后一次出现
// 修改
// .substring 截取
// .concat 连接
// .replace 替代
// .trim 去空格
// .valueOf 可以把每一种类型都转换成字符串
// 改变大小写
// .toLowerCase
// .toUpperCase
// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// StringBuffer
// .length
// .capacity
// .ensureCapacity 设置缓冲区大小
// .setLength 设置缓冲区大小
// .charAt
// .setCharAt
// .setLength
// .getChars 把子字符串赋值给数组
// .append
// .insert
// .reverse 返回被调用对象的翻转对象
// .delete StringBuffer自增加的
// .deleteCharAt StringBuffer自增加的
// .replace StringBuffer自增加的
// .substring
}
}
该博客主要展示了Java中String和StringBuffer的使用。介绍了String的截取、比较、搜索、修改等方法,如charAt、equals等;还介绍了StringBuffer的长度、容量设置及增删改等操作,如length、append等,给出了相应代码示例。

被折叠的 条评论
为什么被折叠?



