Here you can find the source of repeat(String s, int times)
Parameter | Description |
---|---|
s | a parameter |
times | a parameter |
public static String repeat(String s, int times)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { /**//w w w . j a v a 2s . c om * Create a string by repeating a substring by specified times. * @param s * @param times * @return */ public static String repeat(String s, int times) { return repeat(s, times, null); } /** * Create a string by repeating a substring by specified times. * @param s * @param times * @param separator * @return */ public static String repeat(String s, int times, String separator) { String[] arr = new String[times]; for (int i = 0; i < times; i++) { arr[i] = s; } return join(arr, separator); } /** * Join a list of strings by comma. * @param strings * @return */ public static String join(List<String> strings) { return join(strings.toArray(new String[0]), ", "); } /** * Join a list of strings by a separator. * @param strings * @param separator * @return */ public static String join(List<String> strings, String separator) { return join(strings.toArray(new String[0]), separator); } /** * Join an array of strings by comma. * @param strings * @return */ public static String join(String[] strings) { return join(strings, ", "); } /** * Join an array of strings by a separator. * @param strings * @param separator * @return */ public static String join(String[] strings, String separator) { StringBuffer sb = new StringBuffer(); if (strings.length > 0) { sb.append(strings[0]); for (int i = 1; i < strings.length; i++) { sb.append(separator); sb.append(strings[i]); } } return sb.toString(); } }