< prev index next >
src/java.base/share/classes/java/lang/Appendable.java
Print this page
*** 116,121 ****
--- 116,146 ----
*
* @throws IOException
* If an I/O error occurs
*/
Appendable append(char c) throws IOException;
+
+ /**
+ * Appends {@code n} copies of the specified character to this
+ * {@code Appendable}.
+ *
+ * @param c
+ * The character to append
+ * @param n
+ * The number of copies
+ *
+ * @return A reference to this {@code Appendable}
+ *
+ * @throws IOException
+ * If an I/O error occurs
+ * @throws IllegalArgumentException
+ * If {@code n} is negative
+ */
+ default Appendable appendN(char c, int n) throws IOException {
+ if (n < 0) {
+ throw new IllegalArgumentException("Negative number of"
+ + " copies: " + n);
+ }
+ StringBuilder sb = new StringBuilder(n);
+ return append(sb.appendN(c, n));
+ }
}
< prev index next >