Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Default How to resize one String already defined?

    Well my question is simple but I can'f found any way to solve this little problem :D, I will apreciate any kind of help / tip.

    I have one String like:
    Java Code:
    String title = "blabla bla bla"
    Latter I need use the this String in other place but I can use it only if his length is < 29, so if his length is more big than 29 I want just delete the extra "characters" inside the String, how I can do this?

    Thanks

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default Re: How to resize one String already defined?

    First a little conceptual matter: Strings in Java don't change their length (or the characters they contain for that matter). They are said to be immutable (unchanging) which is often a very good thing for instances to be.

    So if you want to use the string, but it's too long you have to create another string to be used. A common idiom (that users will understand) is to use an ellipsis. If you have a string like "The quick brown fox jumps over the lazy dog" and you want to use it in a context where a maximum of 28 characters is allowed you might construct the string "The quick brown fox jumps...".

    Have a look in the String class for useful methods.

  3. #3
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: How to resize one String already defined?

    I think what you need is the substring() method of the String class.
    I like likes!

Similar Threads

  1. Replies: 8
    Last Post: 09-12-2011, 11:36 AM
  2. Replies: 2
    Last Post: 06-16-2011, 10:39 AM
  3. Methods that are NOT defined in interface
    By johto760 in forum New To Java
    Replies: 7
    Last Post: 10-29-2010, 07:31 PM
  4. JAVA_HOME is not defined correctly.
    By mail2vs.dvg1 in forum Advanced Java
    Replies: 2
    Last Post: 06-08-2010, 06:08 PM
  5. User Defined Method
    By overcranked in forum New To Java
    Replies: 6
    Last Post: 04-09-2010, 02:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •