Here you can find the source of repeat(String str, int count)
public static String repeat(String str, int count)
//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); } }