Java ResourceBundle/Property文件接受参数{0}中的字符串数组

Java ResourceBundle/Property文件接受参数{0}中的字符串数组,java,localization,resources,Java,Localization,Resources,有没有一种方法可以将字符串数组传递给资源包,以本地化给定键的未知数量的参数 我有: my.message=List of retired products: {0} getValue(bundle, "my.message", list.toArray()); 这样,结果消息中只显示数组中的第一个项。我想您需要一个循环。不,数组中没有内置的工具。您需要自己用这些值构建一个字符串。例如: StringBuilder products = new StringBuilder(); for (in

有没有一种方法可以将字符串数组传递给资源包,以本地化给定键的未知数量的参数

我有:

my.message=List of retired products: {0}

getValue(bundle, "my.message", list.toArray());

这样,结果消息中只显示数组中的第一个项。

我想您需要一个
循环。

不,数组中没有内置的工具。您需要自己用这些值构建一个字符串。例如:

StringBuilder products = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
    products.append(list.get(i));
    if (i + 2 < list.size()) products.append(", ");
    else if (i + 2 == list.size()) products.append(" and "); // Localize this?
}
getValue(bundle, "my.message", products);
StringBuilder产品=新的StringBuilder();
对于(int i=0;i