Here you can find the source of repeat(String string, int n)
Parameter | Description |
---|---|
string | a parameter |
n | a parameter |
public static String repeat(String string, int n)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; public class Main { /**/*from www. j a v a 2 s. c o m*/ * Repeat a character * * @param c * @param n * @return e.g. '-',5 creates "-----" */ public static String repeat(char c, int n) { char[] chars = new char[n]; Arrays.fill(chars, c); return new String(chars); } /** * Like a monkey with a miniature symbol. The joy of repetition really is in * you. ?? Does this deserve to be a utility method? * * @param string * @param n * @return stringstringstring... */ public static String repeat(String string, int n) { StringBuilder sb = new StringBuilder(string.length() * n); for (int i = 0; i < n; i++) { sb.append(string); } return sb.toString(); } }