Java Formatter Usage formatv(String format, Object[] args)

Here you can find the source of formatv(String format, Object[] args)

Description

Returns a string from a format string and its argument.

License

Open Source License

Declaration

public static String formatv(String format, Object[] args) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2006-2013 AITIA International, Inc.
 * //from w  w  w.  j  a  v  a 2 s . c o  m
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

public class Main {
    private static final java.util.Formatter g_formatter = new java.util.Formatter();

    /** Returns a string from a format string and its argument. */
    public static String formatv(String format, Object[] args) {
        if (args == null || args.length == 0)
            return format;
        synchronized (g_formatter) {
            g_formatter.format(format, args);
            g_formatter.flush();
            StringBuilder s = (StringBuilder) (g_formatter.out());
            String ans = s.toString();
            s.delete(0, s.length());
            return ans;
        }
    }
}

Related

  1. formatLong(long number, int length)
  2. formatMessageException(String format, Object... args)
  3. formatNumber(int number)
  4. formatResponse(Formatter formatter, String response)
  5. formatTzname(final String format, final String letter)
  6. formatZeroDecimals(Number x)
  7. fperfdata(String label, double val, String uom, int warnp, double warn, int critp, double crit, boolean minp, double minv, boolean maxp, double maxv)
  8. generateMacOnIncrease(final String baseMac, final long l)
  9. getCommitCounterStr(final long commitCounter)