public class MessageFormat extends Object
该类提供了强大的消息格式化功能,支持参数替换、数字格式化、日期格式化等。 格式化模式语法类似于java.text.MessageFormat,但提供了更多灵活性。 支持以下格式:
| 构造器和说明 |
|---|
MessageFormat(String pattern)
使用指定的模式创建消息格式化器
|
MessageFormat(String pattern,
Locale locale)
使用指定的模式和区域设置创建消息格式化器
|
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
format(Locale locale,
String pattern,
Object... arguments)
使用指定区域设置、模式和参数直接格式化消息
|
String |
format(Object... arguments)
格式化消息,使用提供的参数替换模式中的占位符
|
static String |
format(String pattern,
Object... arguments)
使用指定模式和参数直接格式化消息
|
static String |
formatWithEmpty(Locale locale,
String pattern,
String emptyMsg,
Object... arguments)
使用指定区域设置、模式、空占位符默认消息和参数直接格式化消息
|
String |
formatWithEmpty(String emptyMsg,
Object... arguments)
格式化消息,针对空占位符指定特定的默认消息
|
static String |
formatWithEmpty(String pattern,
String emptyMsg,
Object... arguments)
使用指定模式、空占位符默认消息和参数直接格式化消息
|
Locale |
getLocale() |
static MessageFormat |
newInstance(Locale locale,
String pattern)
使用指定区域设置创建一个新的消息格式化器实例
|
static MessageFormat |
newInstance(String pattern)
创建一个新的消息格式化器实例
|
String |
toString() |
public MessageFormat(String pattern)
pattern - 格式化模式字符串,不能为空public Locale getLocale()
public String format(Object... arguments)
arguments - 用于替换占位符的参数数组public String formatWithEmpty(String emptyMsg, Object... arguments)
emptyMsg - 空占位符对应的默认消息arguments - 用于替换占位符的参数数组public static MessageFormat newInstance(String pattern)
pattern - 格式化模式字符串public static MessageFormat newInstance(Locale locale, String pattern)
locale - 区域设置pattern - 格式化模式字符串public static String format(String pattern, Object... arguments)
pattern - 格式化模式字符串arguments - 用于替换占位符的参数数组public static String format(Locale locale, String pattern, Object... arguments)
locale - 区域设置pattern - 格式化模式字符串arguments - 用于替换占位符的参数数组public static String formatWithEmpty(String pattern, String emptyMsg, Object... arguments)
pattern - 格式化模式字符串emptyMsg - 空占位符使用的默认消息arguments - 用于替换占位符的参数数组Copyright © 2025 fossc. All rights reserved.