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

StringcreateRepeatedString(char c, int length)
Create a string of the same char
char[] vals = new char[length];
Arrays.fill(vals, c);
return String.valueOf(vals);
StringdeleteRepeatStr(String repeatStr, String separator)
delete this repeat character
if (repeatStr == null) {
    return null;
StringBuffer noRepeatStr = new StringBuffer();
String[] strElement = repeatStr.split(separator);
List strlist = new ArrayList();
for (int i = 0; i < strElement.length; i++) {
    if (!strlist.contains(strElement[i])) {
...
Stringrepeat(String in, int count)
repeat
if ((in == null) || (count < 1))
    return "";
StringBuffer out = new StringBuffer();
for (int i = 0; i < count; i++) {
    out.append(in);
return out.toString();
Stringrepeat(String item, int count)
Creates string where given item string is repeated count times.
StringBuilder result = new StringBuilder();
if (!isEmpty(item))
    for (int i = 0; i < count; i++)
        result.append(item);
return result.toString();
Stringrepeat(String pattern, int count)
repeat
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < count; i++) {
    builder.append(pattern);
return builder.toString();
Stringrepeat(String s, int cnt)
Concatentate the given string cnt times
StringBuffer sb = new StringBuffer();
for (int i = 0; i < cnt; i++) {
    sb.append(s);
return sb.toString();
Stringrepeat(String s, int times)
repeat
StringBuffer sb = new StringBuffer();
for (int i = 0; i < times; i++) {
    sb.append(s);
return sb.toString();
Stringrepeat(String s, int times)
Create a string by repeating a substring by specified times.
return repeat(s, times, null);
Stringrepeat(String s, int times)
Generate a string that repeats/replicates a string a specified number of times.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < times; ++i) {
    sb.append(s);
return sb.toString();
Stringrepeat(String str, int count)
repeat
if (count < 0)
    throw new IllegalArgumentException("count must be positive");
char[] chars = str.toCharArray();
char[] result = new char[chars.length * count];
int resultIdx = 0;
for (int i = 0; i < count; i++, resultIdx += chars.length)
    System.arraycopy(chars, 0, result, resultIdx, chars.length);
return new String(result);
...