Java String Multiply multiply(final String s, final Long factor)

Here you can find the source of multiply(final String s, final Long factor)

Description

multiply

License

Open Source License

Declaration

public static String multiply(final String s, final Long factor) 

Method Source Code

//package com.java2s;
/*/*from w w  w.  ja v  a2 s.co  m*/
 * Copyright 2009 Markus Pielmeier
 *
 * This file is part of rox applet builder.
 *
 * rox applet builder is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * rox applet builder is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with rox applet builder.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    public static String multiply(final String s, final Long factor) {
        final int factorInt = factor.intValue();

        if (factor == 0)
            return "";
        if (factor == 1)
            return s;

        final StringBuilder sb = new StringBuilder(s.length() * factorInt);
        for (int i = 0; i < factorInt; ++i) {
            sb.append(s);
        }

        return sb.toString();
    }
}

Related

  1. multiply(final CharSequence str, final int factor)
  2. multiply(final String string, final int times)
  3. multiply(String original, int times)
  4. multiply(String self, int reps)
  5. multiply(String str11, String str22)