Re: Help creating java.lang.String

From: Andrew McDonagh (news_at_andrewcdonagh.f2s.com)
Date: 12/28/04

  • Next message: Mitja: "Re: which SDK for j2me wireless toolkit on debian?"
    Date: Tue, 28 Dec 2004 00:32:58 +0000
    
    

    Miss. Michelle Heigardt wrote:
    > Hallo NewsGroup, I have this Java to create a blank string of defined
    > size. Is there a nicer way of doing this?
    >
    > Thank you
    > Michelle
    >
    >
    > private String makeString(int sizeOfString)
    > {
    > StringBuffer sb=new StringBuffer("");
    > for (int i=0;i<sizeOfString;i++)
    > sb.append(" ");
    > return sb.toString());
    > }

    I have to ask...why does it have to be a particular sized string?

    as for a nicer way.... eye of the beholder and all that...

    import java.util.Arrays;

    public class StringUtils {

        public static String makeString(int sizeOfString) {
           char[] rawStringArray = new char[sizeOfString];
           Arrays.fill(rawStringArray, ' ');

           return new String(rawStringArray);
        }

    }


  • Next message: Mitja: "Re: which SDK for j2me wireless toolkit on debian?"

    Relevant Pages

    • Re: Help creating java.lang.String
      ... Michelle Heigardt wrote: ... I have this Java to create a blank string of defined ... Is there a nicer way of doing this? ...
      (comp.lang.java.help)
    • Re: use of "return"
      ... at the end of a method, 'return' is indeed not needed, and simply that value will suffice, though i think a return looks nicer;-) ... def method ... in the light of Duck Typing usually no ...
      (comp.lang.ruby)
    • Re: Can you call asp function in asp.net?
      ... I tried to show you the in my opinion nicest version. ... 'this is nicer in ASPX and than all your subs and functions inside that. ... function test(ByVal strValue as String) as String ... 'ByValue is in VBNet/CSharp almost forever more efficient than ByRef ...
      (microsoft.public.dotnet.general)
    • Re: Dumping an array to a web page
      ... Peter Fox wrote: ... string '1', hence the var_dump.If you don't need it the layout of print_r ... is indeed somewhat 'nicer'. ...
      (comp.lang.php)
    • Stringizing escape character tokens, std. or not?
      ... const char *mystr2 = FOO; ... ....but if anyone knows of a nicer way of doing the above, ... C String APIs use too much memory? ...
      (comp.std.c)