创建新的字符串:
Concat(String str)
public native String concat(String str); 字符串的附加 这是个JNI方法是实现在别的c,或者c++文件中, 在原字符串后面加新的str
indexof() // 寻找字符串所出现的位子,源码如下:
public int indexOf(String str, int fromIndex) {
return indexOf(this, str, fromIndex); //this 本字符串
}
定位到
static int indexOf(String source, String target,int fromIndex) {
//先决条件的判断
if (fromIndex >= source.count) {
return (target.count == 0 ? source.count : -1); //寻找字符串长度为0 直接退出
}
if (fromIndex < 0) {
fromIndex = 0; //
}
if (target.count == 0) {
return fromIndex;
}
char first = target.charAt(0);
int max = (source.count - target.count); //定义最大值
//遍历
for (int i = fromIndex; i <= max; i++) {
/* Look for first character. */
if (source.charAt(i)!= first) {
while (++i <= max && source.charAt(i) != first);
}
/* Found first character, now look at the rest of v2 */
if (i <= max) {
int j = i + 1;
int end = j + target.count - 1;
for (int k = 1; j < end && source.charAt(j)
== target.charAt(k); j++, k++);
if (j == end) {
/* Found whole string. */
return i;
}
}
}
return -1;
}
endsWith(string s); //特定结尾
split(string) //分割符
String Buffer
String Buffer 继承AbstractStringBuilder
相同点:
用于处理字符串
提供length,charat
StringBuffer.append
优化stringBuffer : 预先估计设定StringBuffer的缓存量
StringBuffer 线程安全
StringBuilder 是非线程安全
Collection
集合: