Results 1 to 2 of 2
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default formatting String

    I have following code:

    Java Code:
    String formatString = "---%1$-10s---";
    System.out.format(formatString, "MyName");
    Output:
    Java Code:
    ---MyName    ---
    I frankly don't know what %1$ means in the above code :(
    I would appreciate if someone can help.

  2. #2
    rajiv_bang is offline Member
    Join Date
    Nov 2007
    Posts
    11
    Rep Power
    0

    Default

    Hi,

    The format specifier is of type
    %[argument_index$][flags][width]conversion
    Hence in %1$

    1$ = indicates the first argument ie "MyName"
    flags = - (left justify)
    width = 10
    conversion = s (string)

    Please let me know if I was not clear enough.

Similar Threads

  1. formatting..
    By sireesha in forum New To Java
    Replies: 16
    Last Post: 06-26-2009, 08:11 PM
  2. Formatting a number to currency
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 11:59 PM
  3. Data formatting for the <display:table>
    By yuchuang in forum Web Frameworks
    Replies: 3
    Last Post: 12-14-2007, 11:52 AM
  4. Correct Number formatting
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:59 AM
  5. Formatting the date
    By yuchuang in forum New To Java
    Replies: 5
    Last Post: 05-07-2007, 07:08 PM

Posting Permissions

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