Java String Repeat createRepeatedString(char c, int length)

Here you can find the source of createRepeatedString(char c, int length)

Description

Create a string of the same char

License

Open Source License

Parameter

Parameter Description
c the character
length the length

Return

the created string

Declaration

public static String createRepeatedString(char c, int length) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 BestSolution.at and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w w w.j a v a  2s . c  o m
 *     Tom Schindl <tom.schindl@bestsolution.at> - initial API and implementation
 *******************************************************************************/

import java.util.Arrays;

public class Main {
    /**
     * Create a string of the same char
     *
     * @param c
     *            the character
     * @param length
     *            the length
     * @return the created string
     * @since 2.4.0
     */
    public static String createRepeatedString(char c, int length) {
        char[] vals = new char[length];
        Arrays.fill(vals, c);
        return String.valueOf(vals);
    }
}

Related

  1. deleteRepeatStr(String repeatStr, String separator)
  2. repeat(String in, int count)
  3. repeat(String item, int count)
  4. repeat(String pattern, int count)