The answer is in the Formatter
class that is used by the String.format
:
-
The format specifiers for general, character, and numeric types have the following syntax:
%[argument_index$][flags][width][.precision]conversion
The optional argument_index is a decimal integer indicating the position of the argument in the argument list. The first argument is referenced by " 1$
", the second by " 2$
", etc.
The optional flags is a set of characters that modify the output format. The set of valid flags depends on the conversion.
The optional width is a positive decimal integer indicating the minimum number of characters to be written to the output.
The optional precision is a non-negative decimal integer usually used to restrict the number of characters. The specific behavior depends on the conversion.
The required conversion is a character indicating how the argument should be formatted. The set of valid conversions for a given argument depends on the argument's data type.
Translating to Portuguese:
-
Format specifiers for general, character, and numeric types have the following syntax:
%[argument_index$][flags][width][.precision]conversion
The optional argument_index is a decimal integer indicating the position of the argument in the argument list. The first argument is referenced by " 1$
", the second by " 2$
", etc.
The optional flags is a character set that modifies the output format. The set of valid flags depends on conversion .
The optional width is a positive decimal integer indicating the minimum number of characters to be written to the output.
The optional precision is a non-negative decimal integer usually used to restrict the number of characters. The specific behavior depends on conversion .
The required conversion is the character indicating how the argument will be formatted. The set of valid conversions for a given argument depends on the data type of the argument.
In the case of conversion , this is what the Formatter
class specifies, among other things:
'x'
, 'X'
The result is formatted as a hexadecimal integer
Translating:
'x'
, 'X'
The result is formatted as a hexadecimal integer
According to the documentation, the conversions uppercase will produce the output with uppercase and lowercase letters.
As for flags :
'0'
The result will be zero-padded
Translating:
'0'
The result will be completed with zeros [on the left]
That is, in the case of "%1$032X"
, we have the following:
-
%
indicates that the text that follows is a format specifier.
-
1$
is the argument_index that references the first argument of the argument list (it will be the contents of the i
variable).
-
0
is flags which specifies that the number must be completed with leading zeros.
-
32
is the width , that is, the length of the number. That is, 32 characters.
-
X
is conversion , which specifies that the number will be expressed in hexadecimal digits, using uppercase letters for the A-F digits.