The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
June 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Initializaion of a StringBuffer

Posted by Eric Allan Lucas on June 16, 2000 at 11:01 AM

I've got a string buffer that I'd like to load with 476 spaces.
There does not appear to be a method that will work like the c function memset. How do I do this without a loop appending 476 spaces onto the StringBuffer??

This is really a kludge but it's all I've been able to get working:
char[] cc = new char[1] ;
cc[0] = ' ' ;
StringBuffer aa = new StringBuffer(480); //extra room is ok
for ( int x = 0; x < 476; x++ ) {
My Visual Basic Wiz co-worker says "aa = Space(476)" works for him but we're not in VB here :-). I could write a "Space" method using the above loop code but I hope there is something more elegant!
Help is greatly appreciated!



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us