@Nonnull
  public static String getRepeated (@Nonnull final String sElement, @Nonnegative final int nRepeats)
  {
    ValueEnforcer.notNull (sElement, "Element");
    ValueEnforcer.isGE0 (nRepeats, "Repeats");

    final int nElementLength = sElement.length ();

    // Check if result length would exceed int range
    if ((long) nElementLength * nRepeats > Integer.MAX_VALUE)
      throw new IllegalArgumentException ("Resulting string exceeds the maximum integer length");

    if (nElementLength == 0 || nRepeats == 0)
      return "";
    if (nRepeats == 1)
      return sElement;

    // use character version
    if (nElementLength == 1)
      return getRepeated (sElement.charAt (0), nRepeats);

    // combine via StringBuilder
    final StringBuilder ret = new StringBuilder (nElementLength * nRepeats);
    for (int i = 0; i < nRepeats; ++i)
      ret.append (sElement);
    return ret.toString ();
  }
@ Nonnull public static String getRepeated ( @ Nonnull final String sElement , @ Nonnegative final int nRepeats ) { ValueEnforcer . notNull ( sElement , "Element" ) ; ValueEnforcer . isGE0 ( nRepeats , "Repeats" ) ; final int nElementLength = sElement . length ( ) ; if ( ( long ) nElementLength * nRepeats > Integer . MAX_VALUE ) throw new IllegalArgumentException ( "Resulting string exceeds the maximum integer length" ) ; if ( nElementLength == 0 || nRepeats == 0 ) return "" ; if ( nRepeats == 1 ) return sElement ; if ( nElementLength == 1 ) return getRepeated ( sElement . charAt ( 0 ) , nRepeats ) ; final StringBuilder ret = new StringBuilder ( nElementLength * nRepeats ) ; for ( int i = 0 ; i < nRepeats ; ++ i ) ret . append ( sElement ) ; return ret . toString ( ) ; }
Get the passed string element repeated for a certain number of times. Each
string element is simply appended at the end of the string.

@param sElement
The string to get repeated. May not be <code>null</code>.
@param nRepeats
The number of repetitions to retrieve. May not be &lt; 0.
@return A non-<code>null</code> string containing the string element for the
given number of times.