Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6711675

(str) String.format(Object... args) for more compact coding

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 7
    • core-libs

      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)

            jgish Jim Gish (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: