Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Ruby like string interpolation in Java

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ruby like string interpolation in Java

    Hi,

    I am trying to find out if there is any ruby like string interpolation in java...for example :
    ("where is {$color} coffee {$object},"brown","mug") would give me "where is brown coffee mug"

    I have never really worked on ruby myself, but I have heard that its interpolation method makes life really easy when generating dynamic strings or generating queries for a database dynamically.

    Thanks!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Ruby like string interpolation in Java

    Look at the String class's format() method. It will do String substitutions

  3. #3
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Ruby like string interpolation in Java

    In addition to what Norm said, check out the printf() method: PrintStream (Java Platform SE 6)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  4. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Ruby like string interpolation in Java

    I suspect the MessageFormat class is as close as you're likely to get.

Similar Threads

  1. Interpolation of time series data
    By adyehh in forum Java Theory & Questions
    Replies: 0
    Last Post: January 27th, 2011, 11:21 AM
  2. Java Tip Nov 20, 2010 - Spline Interpolation
    By helloworld922 in forum Java Programming Tutorials
    Replies: 0
    Last Post: November 20th, 2010, 12:44 PM
  3. Java Tip Nov 20, 2010 - Spline Interpolation
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: November 20th, 2010, 12:44 PM
  4. [SOLVED] Interpolation Search for Strings ??
    By george in forum Algorithms & Recursion
    Replies: 3
    Last Post: May 18th, 2010, 06:11 AM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM

Tags for this Thread