Here you can find the source of repeat(String s, int times)
Parameter | Description |
---|---|
s | is the string to repeat. |
times | is the number of times to repeat the string. |
public static String repeat(String s, int times)
//package com.java2s; import java.util.List; public class Main { /**/*from w w w . j av a 2 s . co m*/ * Generate a string that repeats/replicates a string a specified number of * times. * * @param s * is the string to repeat. * @param times * is the number of times to repeat the string. * @return a concatenation of times instances of s. */ public static String repeat(String s, int times) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < times; ++i) { sb.append(s); } return sb.toString(); } public static String toString(List<?> arr) { return toString(arr, true); } public static String toString(List<?> arr, boolean square) { return toString(arr.toArray(), square); } public static String toString(Object[] arr) { return toString(arr, true); } public static String toString(Object[] arr, boolean square) { if (arr == null) return "null"; StringBuffer sb = new StringBuffer(); if (square) { sb.append("["); } else { sb.append("("); } for (int i = 0; i < arr.length; ++i) {//Object o : arr ) { if (i > 0) sb.append(","); if (arr[i] == null) { sb.append("null"); } else { sb.append(arr[i].toString()); } } if (square) { sb.append("]"); } else { sb.append(")"); } return sb.toString(); } }