पहले दो वास्तव में, एक ही हैं, क्योंकि printf
के रूप में (source)
public PrintStream printf(String format, Object ... args) {
return format(format, args);
}
कार्यान्वित किया जाता है बाद के दो भी बिल्कुल वैसा ही कर रहे हैं, String.format
के बाद के रूप में (source)
public static String format(String format, Object ... args) {
return new Formatter().format(format, args).toString();
}
कार्यान्वित किया जाता है
अंत में, दूसरा और चौथाई उतना ही कम है, जैसा कि PrintStream.format
(source) के कार्यान्वयन से देखा जा सकता है। हुड के तहत, यह एक नया Formatter
(यदि आवश्यक हो) बनाता है और उस Formatter
पर format
पर कॉल करता है।
public PrintStream format(String format, Object ... args) {
try {
synchronized (this) {
ensureOpen();
if ((formatter == null)
|| (formatter.locale() != Locale.getDefault()))
formatter = new Formatter((Appendable) this);
formatter.format(Locale.getDefault(), format, args);
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
} catch (IOException x) {
trouble = true;
}
return this;
}
स्रोत
2013-05-16 09:29:39