日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

java formatter()_Java Formatter locale()用法及代码示例

發(fā)布時(shí)間:2023/12/10 java 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java formatter()_Java Formatter locale()用法及代码示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

locale()方法是java.util.Formatter的內(nèi)置方法,該方法返回語言環(huán)境。此區(qū)域設(shè)置由格式化程序構(gòu)造設(shè)置。具有語言環(huán)境參數(shù)的該對(duì)象的format方法不會(huì)更改此值。

用法:

public Locale locale()

參數(shù):該函數(shù)不接受任何參數(shù)。

返回值:如果未應(yīng)用任何本地化,則該函數(shù)返回null,否則返回已初始化給格式化程序的語言環(huán)境。

異常注意:如果在調(diào)用函數(shù)之前關(guān)閉了格式化程序,則該函數(shù)將引發(fā)FormatterClosedException。

下面是上述功能的實(shí)現(xiàn):

示例1:

// Java program to implement

// the above function

import java.util.Formatter;

import java.util.Locale;

public class Main {

public static void main(String[] args)

{

// Get the string Buffer

StringBuffer buffer

= new StringBuffer();

// Object creation

Formatter frmt

= new Formatter(buffer,

Locale.CANADA);

// Format a new string

String name = "My name is Gopal Dave";

frmt.format("What is your name? \n%s !",

name);

// Print the Formatted string

System.out.println(frmt);

// Prints the format that has been set

// Initially to the formatter

System.out.println("Locale: "

+ frmt.locale());

}

}

輸出:

What is your name?

My name is Gopal Dave !

Locale: en_CA

示例2:

// Java program to implement

// the above function

import java.util.Formatter;

import java.util.Locale;

public class Main {

public static void main(String[] args)

{

try {

// Get the string Buffer

StringBuffer buffer

= new StringBuffer();

// Object creation

Formatter frmt

= new Formatter(buffer,

Locale.CANADA);

// Format a new string

String name = "My name is Gopal Dave";

frmt.format("What is your name? \n%s !",

name);

// Print the Formatted string

System.out.println(frmt);

// Formatter closed

frmt.close();

// Prints the format that has been set

// Initially to the formatter

System.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

總結(jié)

以上是生活随笔為你收集整理的java formatter()_Java Formatter locale()用法及代码示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。