Smart way of getting a string/stringbuffer of specified length filled in with specific character
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sunil_kuram
Posted On:   Monday, December 9, 2002 10:57 PM

Hi all,
My requirement is get a string/stringbuffer filled in with a specific character and of specific length.

I tried to find a method in JDK api which takes character to be filled with and the length of string and returns a string filled in with that character.

Can anybody show me a smart method of doing this. It would be improper / less efficient to add up characters into a stringbuffer and make up a string. What do you say ?

thanks in adavance.

bye

Sunil.

Re: Smart way of getting a string/stringbuffer of specified length filled in with specific character

Posted By:   Anonymous  
Posted On:   Tuesday, December 10, 2002 01:02 AM

If you want to use methods that are part of the standard distribution, you can:

  • create a char[] of the size you need

  • use the correct Arrays.fill() method to fill with the character you need

  • finally create the String with the correct constructor

About | Sitemap | Contact