choiceformatexam.java

来自「JavaWeb高级特性书中源代码」· Java 代码 · 共 18 行

JAVA
18
字号
import java.text.MessageFormat;
import java.text.ChoiceFormat;
public class ChoiceFormatExam
{
	public static void main(String[] args) throws Exception
	{
		String pattern = "The disk \"{0}\" contains {1}.";
		MessageFormat msgFmt = new MessageFormat(pattern);
		double[] filelimits = {0, 1, 2};
		String[] filepart = {"no files", "one file", "{1,number} files"};
		ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart);
		msgFmt.setFormatByArgumentIndex(1, fileform);
		int fileCount = 100;
		String diskName = "MyDisk";
		Object[] testArgs = {diskName, new Long(fileCount)};
		System.out.println(msgFmt.format(testArgs));
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?