2024年4月26日发(作者:)
标签: 字符串构造函数替换缓冲区截取 it
1、length() 字符串的长度
例:char chars[]={'a','b'.'c'};
String s=new String(chars);
int len=();
2、charAt() 截取一个字符
例:char ch;
ch="abc".charAt(1); 返回'b'
3、getChars() 截取多个字符
void getChars(int sourceStart,int sourceEnd,char target[],int targetStart)
sourceStart指定了子串开始字符的下标,sourceEnd指定了子串结束后的下一个字
符的下标。因此,子串包含从sourceStart到sourceEnd-1的字符。接收字符的数组由
target指定,target中开始复制子串的下标值是targetStart。
例:String s="this is a demo of the getChars method.";
char buf[]=new char[20];
rs(10,14,buf,0);
4、getBytes()
替代getChars()的一种方法是将字符存储在字节数组中,该方法即getBytes()。
5、toCharArray()
6、equals()和equalsIgnoreCase() 比较两个字符串
7、regionMatches() 用于比较一个字符串中特定区域与另一特定区域,它有一个重
载的形式允许在比较中忽略大小写。
boolean regionMatches(int startIndex,String str2,int str2StartIndex,int
numChars)
boolean regionMatches(boolean ignoreCase,int startIndex,String str2,int
str2StartIndex,int numChars)
8、startsWith()和endsWith()
startsWith()方法决定是否以特定字符串开始,endWith()方法决定是否以特定字符串
结束


发布评论