public static String repeat ( String source , int times ) { dbc . precondition ( source != null , "cannot repeat a null source" ) ; dbc . precondition ( times > - 1 , "times must be non negative" ) ; final int srcLen = source . length ( ) ; final long longLen = times * ( long ) srcLen ; final int len = ( int ) longLen ; dbc . precondition ( longLen == len , "resulting String would be too long" ) ; final char [ ] array = new char [ len ] ; for ( int i = 0 ; i != times ; ++ i ) { source . getChars ( 0 , srcLen , array , i * srcLen ) ; } return new String ( array ) ; }
Creates a String by repeating the source string .