I can’t figure out what this %1$d format specifier means. Can someone help me?
int zahl = 100;
System.out.format("A number: %1$d %n", zahl);
>Solution :
1$ represents your first argument which is your zahl variable. %d is the format specifier for integer. The $ convention is used to avoid multiple times your argument is being reused. One example is,
Date date = new Date();
System.out.printf("hours %tH: minutes %tM: seconds %tS%n", date, date, date);
In the above print statement instead of passing your date variable multiple number of times, you can achieve it instead in the following way,
System.out.printf("%1$tH:%1$tM:%1$tS %1$tp %1$tL %1$tN %1$tz %n", date);