class Strings {
/**
* Returns a string consisting of the input string concatenated a given number
* of times. For example, {@code repeat("hey", 3)} returns the string {@code
* "heyheyhey"}.
*
* @param string any non-null string
* @param count the number of times to repeat it; a nonnegative integer
* @return a string containing {@code string} repeated {@code count} times
* (the empty string if {@code count} is zero)
* @throws IllegalArgumentException if {@code count} is negative
*/
static String repeat(String string, int count) {
// If this multiplication overflows, a NegativeArraySizeException or
// OutOfMemoryError is not far behind
StringBuilder builder = new StringBuilder(string.length() * count);
for (int i = 0; i < count; i++) {
builder.append(string);
}
return builder.toString();
}
}