Java String Format stringFormat(String pattern, Object[] arguments)

Here you can find the source of stringFormat(String pattern, Object[] arguments)

Description

add by chen yong 2007-2-5 samples: 1.

License

Open Source License

Parameter

Parameter Description
pattern message format pattern
arguments format arguments

Return

the formatted string

Declaration

public static String stringFormat(String pattern, Object[] arguments) 

Method Source Code

//package com.java2s;
/**//from   ww w.  j av  a2 s .c  om
  * Copyright 2010 ZTEsoft Inc. All Rights Reserved.
  *
  * This software is the proprietary information of ZTEsoft Inc.
  * Use is subject to license terms.
  * 
  * $Tracker List
  * 
  * $TaskId: $ $Date: 9:24:36 AM (May 9, 2008) $comments: create 
  * $TaskId: $ $Date: 3:56:36 PM (SEP 13, 2010) $comments: upgrade jvm to jvm1.5 
  *  
  *  
  */

import java.text.MessageFormat;

public class Main {
    /**
      * add by chen yong 2007-2-5 samples: 1. Object[] arguments = { new
      * Integer(7), new Date(System.currentTimeMillis()), "a disturbance in the
      * Force" };
      * 
      * String result = MessageFormat.format( "At {1,time} on {1,date}, there was
      * {2} on planet {0,number,integer}.", arguments); output: At 13:57:11 on
      * 2007-2-5, there was a disturbance in the Force on planet 7. 2. Object[]
      * objs = {new Double(3.1415)}; String result = MessageFormat.format(
      * "{0,number,#.##}, {0,number,#.#}, {0}",objs); Output: 3.14, 3.1, 3.142
      * 
      * @param pattern
      *            message format pattern
      * @param arguments
      *            format arguments
      * @return the formatted string
      */
    public static String stringFormat(String pattern, Object[] arguments) {
        return MessageFormat.format(pattern, arguments);
    }

    public static String stringFormat(String pattern) {

        return pattern;
    }

    public static String stringFormat(String pattern, Object arg1) {
        Object[] argList = new Object[] { arg1 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2) {
        Object[] argList = new Object[] { arg1, arg2 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3) {
        Object[] argList = new Object[] { arg1, arg2, arg3 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
            Object arg12) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11,
                arg12 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
            Object arg12, Object arg13) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
                arg13 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
            Object arg12, Object arg13, Object arg14) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
                arg13, arg14 };
        return MessageFormat.format(pattern, argList);
    }

    public static String stringFormat(String pattern, Object arg1, Object arg2, Object arg3, Object arg4,
            Object arg5, Object arg6, Object arg7, Object arg8, Object arg9, Object arg10, Object arg11,
            Object arg12, Object arg13, Object arg14, Object arg15) {
        Object[] argList = new Object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12,
                arg13, arg14, arg15 };
        return MessageFormat.format(pattern, argList);
    }
}

Related

  1. getWriterByFormat(final String format)
  2. isDurationFormatPattern(String formatPattern)
  3. isQueryInFormat(String in)
  4. str(final String messageFormat, final Object... args)
  5. StrFormat(String pattern, Object... arguments)
  6. stringFormat(String textPattern, Object... args)