Java Formatter Usage asFormattedStr(String format, String eol, Object... objects)

Here you can find the source of asFormattedStr(String format, String eol, Object... objects)

Description

as Formatted Str

License

Apache License

Declaration

public static String asFormattedStr(String format, String eol, Object... objects) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.Formatter;

public class Main {
    public static String asFormattedStr(String format, String eol, Object... objects) {
        Formatter f = new Formatter();
        String s = f.format(format + "%s", objects, eol).toString();
        f.close();/* w ww  . ja v  a  2  s.  co m*/
        return s;
    }

    public static String asFormattedStr(Formatter f, String format, String eol, Object... objects) {
        String s = f.format(format + "%s", objects, eol).toString();
        return s;
    }

    public static String asFormattedStr(String format, Object... objects) throws Exception {
        Formatter f = new Formatter();
        try {
            String s = f.format(format, objects).toString();
            return s;
        } catch (Exception e) {
            throw new Exception(
                    "Failed to format the values " + Arrays.toString(objects) + " using format:" + format, e);
        } finally {
            f.close();
        }
    }

    public static String asFormattedStr(Formatter f, String format, Object... objects) {
        String s = f.format(format, objects).toString();
        return s;
    }
}

Related

  1. alterationValueToString(double value)
  2. append(final CharSequence seq, final Formatter formatter, final int flags, final int width, final int precision)
  3. assertion(final boolean test, final String fmt, final Object... params)
  4. byte2Mac(final byte[] m)
  5. byteArray2Hex(byte[] hash)
  6. byteArray2Hex(final byte[] hash)