江苏网站建设系统方案,wordpress调用缩略图,建筑公司的愿景和使命,备案网站可以做接码平台么locale()方法是java.util.Formatter的内置方法#xff0c;该方法返回语言环境。此区域设置由格式化程序构造设置。具有语言环境参数的该对象的format方法不会更改此值。用法#xff1a;public Locale locale()参数#xff1a;该函数不接受任何参数。返回值#xff1a;如果未…locale()方法是java.util.Formatter的内置方法该方法返回语言环境。此区域设置由格式化程序构造设置。具有语言环境参数的该对象的format方法不会更改此值。用法public Locale locale()参数该函数不接受任何参数。返回值如果未应用任何本地化则该函数返回null否则返回已初始化给格式化程序的语言环境。异常注意如果在调用函数之前关闭了格式化程序则该函数将引发FormatterClosedException。下面是上述功能的实现示例1:// Java program to implement// the above functionimport java.util.Formatter;import java.util.Locale;public class Main {public static void main(String[] args){// Get the string BufferStringBuffer buffer new StringBuffer();// Object creationFormatter frmt new Formatter(buffer,Locale.CANADA);// Format a new stringString name My name is Gopal Dave;frmt.format(What is your name? \n%s !,name);// Print the Formatted stringSystem.out.println(frmt);// Prints the format that has been set// Initially to the formatterSystem.out.println(Locale: frmt.locale());}}输出What is your name?My name is Gopal Dave !Locale: en_CA示例2:// Java program to implement// the above functionimport java.util.Formatter;import java.util.Locale;public class Main {public static void main(String[] args){try {// Get the string BufferStringBuffer buffer new StringBuffer();// Object creationFormatter frmt new Formatter(buffer,Locale.CANADA);// Format a new stringString name My name is Gopal Dave;frmt.format(What is your name? \n%s !,name);// Print the Formatted stringSystem.out.println(frmt);// Formatter closedfrmt.close();// Prints the format that has been set// Initially to the formatterSystem.out.println(Locale: frmt.locale());}catch (Exception e) {System.out.println(Exception is: e);}}}输出What is your name?My name is Gopal Dave !Exception is: java.util.FormatterClosedException