< prev index next >
src/java.base/share/classes/java/lang/CharSequence.java
Print this page
rev 59316 : 8215401: Add isEmpty default method to CharSequence
Reviewed-by: jlaskey, rriggs, jjg
@@ -86,10 +86,25 @@
* {@code length()}
*/
char charAt(int index);
/**
+ * Returns {@code true} if this character sequence is empty.
+ *
+ * @implNote
+ * The default implementation returns the result of calling {@code length() == 0}.
+ *
+ * @return {@code true} if {@link #length()} is {@code 0}, otherwise
+ * {@code false}
+ *
+ * @since 15
+ */
+ default boolean isEmpty() {
+ return this.length() == 0;
+ }
+
+ /**
* Returns a {@code CharSequence} that is a subsequence of this sequence.
* The subsequence starts with the {@code char} value at the specified index and
* ends with the {@code char} value at index {@code end - 1}. The length
* (in {@code char}s) of the
* returned sequence is {@code end - start}, so if {@code start == end}
< prev index next >