Here you can find the source of repeat(String string, int times)
public static String repeat(String string, int times)
//package com.java2s; /*/*w ww .j a v a2 s .com*/ * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ import java.util.Arrays; public class Main { public static String repeat(String string, int times) { StringBuilder buf = new StringBuilder(string.length() * times); for (int i = 0; i < times; i++) { buf.append(string); } return buf.toString(); } public static String repeat(String string, int times, String deliminator) { StringBuilder buf = new StringBuilder((string.length() * times) + (deliminator.length() * (times - 1))) .append(string); for (int i = 1; i < times; i++) { buf.append(deliminator).append(string); } return buf.toString(); } public static String repeat(char character, int times) { char[] buffer = new char[times]; Arrays.fill(buffer, character); return new String(buffer); } public static String toString(Object[] array) { int len = array.length; if (len == 0) { return ""; } StringBuilder buf = new StringBuilder(len * 12); for (int i = 0; i < len - 1; i++) { buf.append(array[i]).append(", "); } return buf.append(array[len - 1]).toString(); } }