String.format("%1s","").equals("")); // --> return false !
String.format("%1s","").equals(" ")); // --> return true !
The space is specified by the minimum width value 1
in the format specifier
String.format("%1s","").equals(" ")
^
You wanted to add an argument index like this
String.format("%1$s", ""); //returns ""
String.format("%2$s %1$s", "a", "b"); //returns "b a"
Your code defined a "width"
String.format("%3s", ""); // returns " ";
String.format("%3s", "a"); // returns " a";
String.format("%-3s", "a"); // returns "a ";
Read this for more info: http://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With