Java String Repeat repeat(String string, int times)

Here you can find the source of repeat(String string, int times)

Description

repeat

License

LGPL

Declaration

public static String repeat(String string, int times) 

Method Source Code

//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();
    }
}

Related

  1. repeat(String str, int repeat)
  2. repeat(String str, int repeat)
  3. repeat(String string, int n)
  4. repeat(String string, int number)
  5. repeat(String string, int times)
  6. repeat(String val, int n)
  7. repeat(String value, int times)
  8. repeatChar(String c, int repeatCount)
  9. repeatImplodeString(String string, int length, String seperator)