JDK-6711675 : (str) String.format(Object... args) for more compact coding
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2008-06-06
  • Updated: 2012-08-09
  • Resolved: 2012-08-09
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
I request that the following convenience method is added to java.lang.String:

public static String format(Object... args) {
    String.format(this, args);
}



JUSTIFICATION :
An instance-method would allow simple String formatting to be done in a more compact and readable manner.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Adding the above method to java.lang.String would allow this convenient syntax:

   String s = "%1 is %2 years old".format(name, years);

... synonymous with the current ...

   String s = String.format("%1 is %2 years old", name, years);


ACTUAL -
(not applicable)

---------- BEGIN SOURCE ----------
(not applicable)
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
(not applicable)