Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

printf(String, Object) and format(String, Object) methods

 
Steve Ng
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear ranchers,

According to K&B book, the format string should be as follows:

[Array index] [Flags] [Width] [.Precision] [Conversion]

And the array index is starting from 1: 1$, 2$ ...

Flags: +, - , 0, , , (

Width: integer number

Conversion: b, c, d, s, f

My question is:

How many flags can be used in combination? I have tried and it seems to m that maximum only 2 flags in be used together.

For example: System.out.printf("%2$(010d*", "Hello", -200);

How does the compiler interpret the format string from left to right? For example: how does it differenciate between flags and width and conversion etc.

Thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic