< prev index next >
src/java.base/share/classes/java/lang/String.java
Print this page
rev 52979 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: TBD
*** 662,672 ****
*
* @return the length of the sequence of characters represented by this
* object.
*/
public int length() {
! return value.length >> coder();
}
/**
* Returns {@code true} if, and only if, {@link #length()} is {@code 0}.
*
--- 662,672 ----
*
* @return the length of the sequence of characters represented by this
* object.
*/
public int length() {
! return isLatin1() ? value.length : value.length >> UTF16;
}
/**
* Returns {@code true} if, and only if, {@link #length()} is {@code 0}.
*
*** 1941,1952 ****
* of this {@code String}.
* @return a string that represents the concatenation of this object's
* characters followed by the string argument's characters.
*/
public String concat(String str) {
! int olen = str.length();
! if (olen == 0) {
return this;
}
if (coder() == str.coder()) {
byte[] val = this.value;
byte[] oval = str.value;
--- 1941,1951 ----
* of this {@code String}.
* @return a string that represents the concatenation of this object's
* characters followed by the string argument's characters.
*/
public String concat(String str) {
! if (str.isEmpty()) {
return this;
}
if (coder() == str.coder()) {
byte[] val = this.value;
byte[] oval = str.value;
*** 1954,1963 ****
--- 1953,1963 ----
byte[] buf = Arrays.copyOf(val, len);
System.arraycopy(oval, 0, buf, val.length, oval.length);
return new String(buf, coder);
}
int len = length();
+ int olen = str.length();
byte[] buf = StringUTF16.newBytesFor(len + olen);
getBytes(buf, 0, UTF16);
str.getBytes(buf, len, UTF16);
return new String(buf, UTF16);
}
*** 2314,2324 ****
list.add(substring(off, length()));
// Construct result
int resultSize = list.size();
if (limit == 0) {
! while (resultSize > 0 && list.get(resultSize - 1).length() == 0) {
resultSize--;
}
}
String[] result = new String[resultSize];
return list.subList(0, resultSize).toArray(result);
--- 2314,2324 ----
list.add(substring(off, length()));
// Construct result
int resultSize = list.size();
if (limit == 0) {
! while (resultSize > 0 && list.get(resultSize - 1).isEmpty()) {
resultSize--;
}
}
String[] result = new String[resultSize];
return list.subList(0, resultSize).toArray(result);
< prev index next >