Java String toUpperCase()
方法有两种变体。第一个变量使用给定Locale的规则将此String中的所有字符转换为大写。 这相当于调用toUpperCase(Locale.getDefault())
。
第二个变体将locale
作为在转换为大写时使用的参数。
语法
下面是这个方法的语法 -
public String toUpperCase(Locale locale)
参数
locale
- 指定区域。
返回值
- 它返回转换为大写后的字符串。
示例
import java.util.*;
public class Test {
public static void main(String[] args) {
String str1 = "Self Learning Center";
// using the default system Locale
Locale defloc = Locale.getDefault();
// converts all upper case letters in to Upper case letters
System.out.println("string value = " + str1.toUpperCase(defloc));
str1 = "WWW.Kaops.COM";
System.out.println("string value = " + str1.toUpperCase(defloc));
}
}
执行上面示例代码,得到以下结果:
string value = SELF LEARNING CENTER
string value = WWW.KAOPS.COM
上一篇:
java中方法重载和方法重写的区别
下一篇:无