Create a string with n characters.
Posted
by C. Ross
on Stack Overflow
See other posts from Stack Overflow
or by C. Ross
Published on 2010-05-10T17:21:46Z
Indexed on
2010/05/10
17:24 UTC
Read the original article
Hit count: 188
Is there a way in java to create a string with a specified number of a specified character? In my case I would need to create a string with 10 spaces. My current code is:
StringBuffer outputBuffer = new StringBuffer(length);
for (int i = 0; i < length; i++){
outputBuffer.append(" ");
}
return outputBuffer.toString();
Is there a better way to accomplish the same thing. In particular I'd like something that is fast (in terms of execution).
© Stack Overflow or respective owner