Java String Repeat repeat(String str, int count)

Here you can find the source of repeat(String str, int count)

Description

repeat

License

Open Source License

Declaration

public static String repeat(String str, int count) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static String repeat(String str, int count) {
        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);
    }/* w  w w.j a  va  2s.c om*/

    public static String repeat(char c, int count) {
        if (count < 0)
            throw new IllegalArgumentException("count must be positive");

        char[] result = new char[count];
        Arrays.fill(result, c);
        return new String(result);
    }
}

Related

  1. repeat(String pattern, int count)
  2. repeat(String s, int cnt)
  3. repeat(String s, int times)
  4. repeat(String s, int times)
  5. repeat(String s, int times)
  6. repeat(String str, int repeat)
  7. repeat(String str, int repeat)
  8. repeat(String string, int n)
  9. repeat(String string, int number)