听起来你想要一个ChoiceFormat http://java.sun.com/docs/books/tutorial/i18n/format/choiceFormat.html,或者至少通过 a 使用一个MessageFormat http://java.sun.com/javase/6/docs/api/java/text/MessageFormat.html:
public static void main(String... args) {
String[] formats = {
// NOTE - In a real app, you'd fetch the format strings from a language,
// file, not hard-code them in your program. Obviously.
"{0,number} {0,choice,0#years|1#year|1<years}", // english
"{0,number} {0,choice,0#años|1#año|1<años}", // spanish
"{0,number} {0,choice,1#[fewer than 2]|2#lata|4<lat}", // polish
"{0,number} år", // swedish - singular and plural forms look the same!
};
int[] years = {0, 1, 2, 3, 4, 5, 6};
for (int year : years) {
for (String format : formats) {
System.out.println(MessageFormat.format(format, year));
}
System.out.println();
}
}
在你的程序中,你当然会得到format
来自字符串文件的字符串。