-1

有没有办法获取 MessageFormat 对象模式的最大索引参数?例如:

  1. "Dear {0}, some text {0} text"-> 1
  2. "Dear {0}, some text {1} text"-> 2
  3. "{0,choice,0#0 User|1#User|1<{1} Users}"-> 2
4

1 回答 1

0

如果您使用过一次,您可以使用:

 MessageFormat format = new MessageFormat("Hello {0}, {1}");
// here somewhere you use it
 System.out.println(String.format("Get max index -- %d", new HashSet(Arrays.asList(format.getFormats())).size()));

这打印:

Get max index -- 2

于 2019-12-20T08:21:06.350 回答