src/share/classes/java/lang/String.java

Print this page




2765      * Returns a formatted string using the specified format string and
2766      * arguments.
2767      *
2768      * <p> The locale always used is the one returned by {@link
2769      * java.util.Locale#getDefault() Locale.getDefault()}.
2770      *
2771      * @param  format
2772      *         A <a href="../util/Formatter.html#syntax">format string</a>
2773      *
2774      * @param  args
2775      *         Arguments referenced by the format specifiers in the format
2776      *         string.  If there are more arguments than format specifiers, the
2777      *         extra arguments are ignored.  The number of arguments is
2778      *         variable and may be zero.  The maximum number of arguments is
2779      *         limited by the maximum dimension of a Java array as defined by
2780      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
2781      *         The behaviour on a
2782      *         <tt>null</tt> argument depends on the <a
2783      *         href="../util/Formatter.html#syntax">conversion</a>.
2784      *
2785      * @throws  IllegalFormatException
2786      *          If a format string contains an illegal syntax, a format
2787      *          specifier that is incompatible with the given arguments,
2788      *          insufficient arguments given the format string, or other
2789      *          illegal conditions.  For specification of all possible
2790      *          formatting errors, see the <a
2791      *          href="../util/Formatter.html#detail">Details</a> section of the
2792      *          formatter class specification.
2793      *
2794      * @throws  NullPointerException
2795      *          If the <tt>format</tt> is <tt>null</tt>
2796      *
2797      * @return  A formatted string
2798      *
2799      * @see  java.util.Formatter
2800      * @since  1.5
2801      */
2802     public static String format(String format, Object... args) {
2803         return new Formatter().format(format, args).toString();
2804     }
2805 


2809      *
2810      * @param  l
2811      *         The {@linkplain java.util.Locale locale} to apply during
2812      *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
2813      *         is applied.
2814      *
2815      * @param  format
2816      *         A <a href="../util/Formatter.html#syntax">format string</a>
2817      *
2818      * @param  args
2819      *         Arguments referenced by the format specifiers in the format
2820      *         string.  If there are more arguments than format specifiers, the
2821      *         extra arguments are ignored.  The number of arguments is
2822      *         variable and may be zero.  The maximum number of arguments is
2823      *         limited by the maximum dimension of a Java array as defined by
2824      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
2825      *         The behaviour on a
2826      *         <tt>null</tt> argument depends on the <a
2827      *         href="../util/Formatter.html#syntax">conversion</a>.
2828      *
2829      * @throws  IllegalFormatException
2830      *          If a format string contains an illegal syntax, a format
2831      *          specifier that is incompatible with the given arguments,
2832      *          insufficient arguments given the format string, or other
2833      *          illegal conditions.  For specification of all possible
2834      *          formatting errors, see the <a
2835      *          href="../util/Formatter.html#detail">Details</a> section of the
2836      *          formatter class specification
2837      *
2838      * @throws  NullPointerException
2839      *          If the <tt>format</tt> is <tt>null</tt>
2840      *
2841      * @return  A formatted string
2842      *
2843      * @see  java.util.Formatter
2844      * @since  1.5
2845      */
2846     public static String format(Locale l, String format, Object... args) {
2847         return new Formatter(l).format(format, args).toString();
2848     }
2849 




2765      * Returns a formatted string using the specified format string and
2766      * arguments.
2767      *
2768      * <p> The locale always used is the one returned by {@link
2769      * java.util.Locale#getDefault() Locale.getDefault()}.
2770      *
2771      * @param  format
2772      *         A <a href="../util/Formatter.html#syntax">format string</a>
2773      *
2774      * @param  args
2775      *         Arguments referenced by the format specifiers in the format
2776      *         string.  If there are more arguments than format specifiers, the
2777      *         extra arguments are ignored.  The number of arguments is
2778      *         variable and may be zero.  The maximum number of arguments is
2779      *         limited by the maximum dimension of a Java array as defined by
2780      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
2781      *         The behaviour on a
2782      *         <tt>null</tt> argument depends on the <a
2783      *         href="../util/Formatter.html#syntax">conversion</a>.
2784      *
2785      * @throws  java.util.IllegalFormatException
2786      *          If a format string contains an illegal syntax, a format
2787      *          specifier that is incompatible with the given arguments,
2788      *          insufficient arguments given the format string, or other
2789      *          illegal conditions.  For specification of all possible
2790      *          formatting errors, see the <a
2791      *          href="../util/Formatter.html#detail">Details</a> section of the
2792      *          formatter class specification.
2793      *
2794      * @throws  NullPointerException
2795      *          If the <tt>format</tt> is <tt>null</tt>
2796      *
2797      * @return  A formatted string
2798      *
2799      * @see  java.util.Formatter
2800      * @since  1.5
2801      */
2802     public static String format(String format, Object... args) {
2803         return new Formatter().format(format, args).toString();
2804     }
2805 


2809      *
2810      * @param  l
2811      *         The {@linkplain java.util.Locale locale} to apply during
2812      *         formatting.  If <tt>l</tt> is <tt>null</tt> then no localization
2813      *         is applied.
2814      *
2815      * @param  format
2816      *         A <a href="../util/Formatter.html#syntax">format string</a>
2817      *
2818      * @param  args
2819      *         Arguments referenced by the format specifiers in the format
2820      *         string.  If there are more arguments than format specifiers, the
2821      *         extra arguments are ignored.  The number of arguments is
2822      *         variable and may be zero.  The maximum number of arguments is
2823      *         limited by the maximum dimension of a Java array as defined by
2824      *         <cite>The Java&trade; Virtual Machine Specification</cite>.
2825      *         The behaviour on a
2826      *         <tt>null</tt> argument depends on the <a
2827      *         href="../util/Formatter.html#syntax">conversion</a>.
2828      *
2829      * @throws  java.util.IllegalFormatException
2830      *          If a format string contains an illegal syntax, a format
2831      *          specifier that is incompatible with the given arguments,
2832      *          insufficient arguments given the format string, or other
2833      *          illegal conditions.  For specification of all possible
2834      *          formatting errors, see the <a
2835      *          href="../util/Formatter.html#detail">Details</a> section of the
2836      *          formatter class specification
2837      *
2838      * @throws  NullPointerException
2839      *          If the <tt>format</tt> is <tt>null</tt>
2840      *
2841      * @return  A formatted string
2842      *
2843      * @see  java.util.Formatter
2844      * @since  1.5
2845      */
2846     public static String format(Locale l, String format, Object... args) {
2847         return new Formatter(l).format(format, args).toString();
2848     }
2849