0

I saw some code with something like

String.format("%3d\t%s" , stuff, stuff).

What does the stuff in the quotation marks mean? I know \t is just a tab, but I do not know what the %'s and other things are.

Also, are there any more of those types of symbols that can be used for formatting Strings?

3
  • 5
    docs.oracle.com/javase/7/docs/api/java/util/… Commented Apr 24, 2014 at 0:12
  • 4
    The documentation is actually to be found on the java.util.Formatter class API, not printf. Commented Apr 24, 2014 at 0:12
  • Here is the link for the formatter docs. Commented Apr 24, 2014 at 0:13

2 Answers 2

1

String.format takes a printf format string. Java's format is documented in the JDK documentation for java.lang.String.

The format string you are using breaks down as follows:

  • %3d format (convert) the first argument into a 3 digit integer
  • \t a tab character
  • %s format (convert) the next (second) argumet as a string
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know much about Java but in c c++ means an 3 spaces integer first(%3d) and a string (%s), the values after commas are the variables that take their positions. Maybe a variant of printf method

2 Comments

You're right in spirit, but adding a link to the Formatter API would help in a big way.
I know. But I'm on my phone. I have no many options but your right 100%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.