不是。
或b任一为null,均会抛出空指针异常;
public String concat(String str) {
int otherLen = str.length();
if (otherLen == 0) {
return this;
}
int len = value.length;
char buf[] = Arrays.copyOf(value, len + otherLen);
str.getChars(buf, len);
return new String(buf, true);
}
java中两个字符串怎么连接?
String类的方法:
①利用运算符"+"
②public String concat(String str)进行字符串的拼接操作
StringBuffer的方法:
①public StringBuffer append(String str)将str添加到当前字符串缓冲区的字符序列的末尾
②public StringBuffer insert(int offset,String str)在当前字符串缓冲区的字符序列的下标
索引offset插入str。如果offset等于旧长度,则str添加在字符串缓冲区的尾部。