Android 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 s, int num)
repeat
StringBuilder sb = new StringBuilder();
for (int i = 0; i < num; ++i) {
    sb.append(s);
return sb.toString();
Stringrepeat(String str, String separator, int repeat)

Repeat a String repeat times to form a new String, with a String separator injected each time.

if (str == null || separator == null) {
    return repeat(str, repeat);
} else {
    String result = repeat(str + separator, repeat);
    return removeEnd(result, separator);
Stringrepeat(String str, int repeat)
repeat
if (str == null) {
    return null;
if (repeat < 1) {
    return EMPTY;
int inputLen = str.length();
if (inputLen == 0 || repeat == 1) {
...
Stringrepeat(String str, int repeat)

Repeat a String repeat times to form a new String.

 StringUtils.repeat(null, 2) = null StringUtils.repeat("", 0)   = "" StringUtils.repeat("", 2)   = "" StringUtils.repeat("a", 3)  = "aaa" StringUtils.repeat("ab", 2) = "abab" StringUtils.repeat("a", -2) = "" 
if (str == null) {
    return null;
if (repeat <= 0) {
    return EMPTY;
int inputLength = str.length();
if (repeat == 1 || inputLength == 0) {
...