On 13 Jul 2010 15:01:35 GMT, Andreas Leitgeb
<avl@gamma.logic.tuwien.ac.at> wrote, quoted or indirectly quoted
someone who said :
It seems so basic that I can't believe such a feature wasn't in
the standard library:
it is part of the common11 tools for JDK 1.1+
http://mindprod.com/products1.html#COMMON11
The method is called StringTools.rep
/**
* Produce a String of a given repeating character.
*
* @param c the character to repeat
* @param count the number of times to repeat
*
* @return String, e.g. rep('*',4) returns "****"
* @noinspection WeakerAccess,SameParameterValue
*/
public static String rep( char c, int count )
{
if ( c == ' '&& count<= SOMESPACES.length() )
{
return SOMESPACES.substring( 0, count );
}
char[] s = new char[count];
for ( int i = 0; i< count; i++ )
{
s[ i ] = c;
}
return new String( s ).intern();
}
/**
* used to efficiently generate Strings of spaces of varying
length
*/
private static final String SOMESPACES = " ";
where the pool storage is and what the cost of using it is. The only
time I use that method is when generating keys for a Properties class.