Java Utililty Methods String Repeat

List of utility methods to do String Repeat

Description

The list of methods to do String Repeat are organized into topic(s).

Method

Stringrepeat(String str, int repeat)
repeat
StringBuilder buffer = new StringBuilder(repeat * str.length());
for (int i = 0; i < repeat; i++) {
    buffer.append(str);
return buffer.toString();
Stringrepeat(String str, int repeat)

Repeat a String n times to form a new string.

StringBuffer buffer = new StringBuffer(repeat * str.length());
for (int i = 0; i < repeat; i++) {
    buffer.append(str);
return buffer.toString();
Stringrepeat(String string, int n)
Like a monkey with a miniature symbol.
StringBuilder sb = new StringBuilder(string.length() * n);
for (int i = 0; i < n; i++) {
    sb.append(string);
return sb.toString();
Stringrepeat(String string, int number)
repeat
final StringBuilder builder = new StringBuilder();
repeat(string, number, builder);
return builder.toString();
Stringrepeat(String string, int times)
repeat
StringBuilder buf = new StringBuilder(string.length() * times);
for (int i = 0; i < times; i++) {
    buf.append(string);
return buf.toString();
Stringrepeat(String string, int times)
Returns a string that is formed by the repetition of a provided string a given number of times.
if (times < 0)
    throw new IllegalArgumentException("Argument 'times' cannot be less than 0");
if (string == null)
    throw new IllegalArgumentException("Argument 'string' cannot be null");
if (times == 1)
    return string;
if (times == 0 || string.length() == 0)
    return "";
...
Stringrepeat(String val, int n)
Return n repetitions of a string, which is usually a single character.
StringBuffer sb = new StringBuffer();
for (int i = 0; i < n; i++) {
    sb.append(val);
return sb.toString();
Listrepeat(String value, int times)
Repeats a String literal N times.
List<String> outList = new ArrayList<String>(times);
for (int i = 0; i < times; i++) {
    outList.add(value);
return outList;
StringrepeatChar(String c, int repeatCount)
Creates a string with the specified length.
char[] chArray = new char[repeatCount];
Arrays.fill(chArray, c.charAt(0));
return String.valueOf(chArray);
StringrepeatImplodeString(String string, int length, String seperator)
repeat Implode String
if (length == 0) {
    return "";
} else {
    String[] strings = new String[length];
    Arrays.fill(strings, string);
    return implodeString(strings, seperator);