user3287300
user3287300

Reputation: 151

String.format( ) format arguments

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?

Upvotes: 0

Views: 1627

Answers (2)

Kyle Burton
Kyle Burton

Reputation: 27528

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

Upvotes: 1

user3477273
user3477273

Reputation:

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

Upvotes: 0

Related Questions