increase string length

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eyeofsoul
    New Member
    • Sep 2007
    • 31

    #1

    increase string length

    how do i increase a string into default lenght?
    for example i put a string, java.how to transform the string to for example 24 character in it?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by eyeofsoul
    how do i increase a string into default lenght?
    for example i put a string, java.how to transform the string to for example 24 character in it?
    There is no such thing as a 'default string length', maybe zero, but that isn't
    its default length. Read the API documentation for the String class and note
    that Strings are immutable objects. Also have a look at the StringBuilder class.

    kind regards,

    Jos

    Comment

    • eyeofsoul
      New Member
      • Sep 2007
      • 31

      #3
      what i mean is that if i insert a string, which is "java".can i increase the length the string into 24 char after some operation?

      Comment

      • sukatoa
        Contributor
        • Nov 2007
        • 539

        #4
        Originally posted by eyeofsoul
        what i mean is that if i insert a string, which is "java".can i increase the length the string into 24 char after some operation?
        Maybe you mean StringBuffer?!! StringBuffer can change its current allocated length and it is extendable...

        After this implementation, you can convert it directly to String...

        See this


        Hopefully it helps,
        Sukatoa

        Comment

        • eyeofsoul
          New Member
          • Sep 2007
          • 31

          #5
          nope.string buffer need you to manually input the char that we want to.in my case i want "some" process which can help the string to be expand to 24 char by the process automatically.

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            There's not a lot of automagic in programming! It's also still not clear what your context is, but gazing into my crystal ball, I see a need to format fixed width columns of output. Formatter is designed to support that:



            Format methods also pop up in java.io.PrintWr iter and PrintStream (aka System.out).

            Comment

            • sukatoa
              Contributor
              • Nov 2007
              • 539

              #7
              Originally posted by eyeofsoul
              nope.string buffer need you to manually input the char that we want to.in my case i want "some" process which can help the string to be expand to 24 char by the process automatically.
              If i were to implement that,

              If i have a string "anything" and in the process should add 24 char, i will convert my string into char array by not using toCharArray, i will allocate the char array in length of anything + 24, then copy the characters into char array...

              Code:
              charr[x] = string.charAt(x);
              After that, convert the char array into String...

              If this is too far again to your idea, then i can't help you as of now...

              Sukatoa

              Comment

              Working...