Cheatsheet: Java String.format
Basic Syntax
The `String.format` method formats strings using placeholders. Placeholders start with `%` and are followed by format specifiers.
Multiple placeholders can be used, and arguments are matched in the same order they appear.
Handling Duplicated Arguments
Using the same argument multiple times by repeating it in the argument list.
Using positional indexing to refer to the same argument multiple times.
Using the `<` symbol to reuse the last argument without repeating it.
Format Specifiers
Common format specifiers include `%s` for strings, `%d` for integers, and `%f` for floating-point numbers.
Formatting numbers with leading zeros.
Specifying width and alignment for strings.
Advanced Formatting Techniques
Using `%%` to include a literal `%` in the formatted string.
Combining argument indexing and format specifiers.
Using locale for formatting (e.g., currency or date).