Search code examples
javastringstring.format

What does the R in "%sR" do in the String.format()


"%-25s%-15d%n" is the text I used to format a line, but the books answer used "%-25sR%-15d%n", and I could not find out what the R does here.


Solution

  • In the code that you show, R is nothing more than a String literal. It is not used by the String Formatter in any format-specific fashion.

    "%-25sR%-15d%n" 
    

    The format specifiers in the code above is the %-25s, %-15d and the %n. All other characters are String literals.

    Note that per the java.util.Formatter API, there is an R format specifier that is used for:

    Time formatted for the 24-hour clock as "%tH:%tM"

    But this has nothing to do with your question or posted code.