Skip to content

Glossary: Data Structures and Algorithms in Java

Format codes (%02d, %-12s, %4d)

Also written: %02d, %-7s, %-12s, %4d, format code

Codes in `String.format` that control how a value prints: `%02d` prints a whole number at least 2 characters wide with a leading zero (9 becomes `09`), `%-12s` pads text on the right to 12 characters, and `%4d` right-aligns a number in 4 characters.

Where the book teaches it