Easiest way to initialize a string builder to a random number of the same character

R

Reporter

Is there something simpler than this?

StringBuilder sb = new StringBuilder();
int s;

for (int i=0; i<s; i++){ sb.append(' '); }
 
T

Tom Hawtin

Reporter said:
Is there something simpler than this?

StringBuilder sb = new StringBuilder();
int s;

for (int i=0; i<s; i++){ sb.append(' '); }

Is it important to do something random like that 'simply'?

You could write:

char[] cs = new char;
java.util.Arrays.fill(cs, ' ');
StringBuilder buff = new StringBuilder().append(cs);

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top