Java: what is the difference between format specifiers% X and% H?
Looking at the specification page, I see that% h calls integer Tohexstring(), but I can't find any actual difference between the two specifiers
Can you give an example of how using the to specifier on the same input will produce different results?
System.out.println(String.format("%1$h %1$x",123));
This print
7b 7b
Solution
%The H specifier calls hashcode on its parameters (assuming it is not null, when you get "null"), while the% x specifier just formats its parameters as hexadecimal integers This makes a big difference if the formatted thing is not an integer See the example here:
http://developer.android.com/reference/java/util/Formatter.html
In particular, the fact that integers get the same result is integer Hashcode returns the result of the integer itself:
http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#hashCode%28%29