Java Utililty Methods Message Format

List of utility methods to do Message Format

Description

The list of methods to do Message Format are organized into topic(s).

Method

Stringformat(String pattern, Object... args)
Format a given string pattern and a list of arguments as defined by MessageFormat
if (args != null && args.length > 0) {
    return MessageFormat.format(pattern, args);
} else
    return String.valueOf(pattern);
Stringformat(String pattern, String[] replacements)
format
return java.text.MessageFormat.format(pattern, (Object[]) replacements);
Stringformat(String str, int replacement)
Formats the string with replacement values
return MessageFormat.format(str, new Object[] { Integer.toString(replacement) });
Stringformat(String str, Object... arguments)
Formats UI strings.
str = str.replaceAll("'", "''");
return MessageFormat.format(str, arguments);
Stringformat(String textPattern, Object... args)
Formats the given String of text.
return messageFormat(stringFormat(textPattern, args), args);
StringformatAsNumber(double value)
format As Number
BigDecimal valueOf = BigDecimal.valueOf(value);
BigDecimal integerPart = BigDecimal.valueOf(valueOf.longValue());
BigDecimal fractional = valueOf.subtract(integerPart);
String fraction = fractional.toPlainString();
int indexOfDot = fraction.indexOf('.') + 1;
String sign = fraction.startsWith("-") ? "-" : "";
fraction = fraction.length() > indexOfDot ? fraction.substring(indexOfDot) : fraction;
if (fraction.equals("0")) {
...
StringformatCause(final String message, final Throwable cause, final Object... args)
format Cause
if (cause == null) {
    return format(message, args);
} else {
    return formatThrowable(format(message, args), cause);
StringformatDuring(long mss, String pattern)
format During
long days = mss / (1000 * 60 * 60 * 24);
long hours = (mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
long minutes = (mss % (1000 * 60 * 60)) / (1000 * 60);
long seconds = (mss % (1000 * 60)) / 1000;
return MessageFormat.format(pattern, days, hours, minutes, seconds);
StringformatError(Map.Entry entry, String errorPlural, String errorSingular)
format Error
int count = entry.getValue();
if (count > 1) {
    return MessageFormat.format(errorPlural, count, entry.getKey());
} else {
    return MessageFormat.format(errorSingular, entry.getKey());
StringformatMessage(final String pattern, final Object... params)
format Message
try {
    return MessageFormat.format(pattern, params);
} catch (Exception e) {
    return '!' + pattern + '!';