< 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,11 +662,11 @@
*
* @return the length of the sequence of characters represented by this
* object.
*/
public int length() {
- return value.length >> coder();
+ return isLatin1() ? value.length : value.length >> UTF16;
}
/**
* Returns {@code true} if, and only if, {@link #length()} is {@code 0}.
*
@@ -1941,12 +1941,11 @@
* 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) {
+ if (str.isEmpty()) {
return this;
}
if (coder() == str.coder()) {
byte[] val = this.value;
byte[] oval = str.value;
@@ -1954,10 +1953,11 @@
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,11 +2314,11 @@
list.add(substring(off, length()));
// Construct result
int resultSize = list.size();
if (limit == 0) {
- while (resultSize > 0 && list.get(resultSize - 1).length() == 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 >