Java字符(串)的大小写转换

一、字符串的大小写转换

java中String类中的toLowerCase()和toUpperCase()方法分别能够将字符串中的字母转换为小写和大写。

示例:

public static void main(String[] ags){       
      String s = "The Day Is Good";                        
      System.out.println(s.toLowerCase());   //输出"the day is good"            
      System.out.println(s.toUpperCase());    //输出"THE DAY IS GOOD"      

}

输出结果:

the day is goodTHE DAY IS GOOD

二、字符的大小写转换

所提供的方法大同小异,java.lang中Character类的toLowerCase(Char ch)和toUpperCase(Char ch)方法分别能对字符进行大小写转换。

示例:

public static void main(String[] ags){      
    Char a='A';      
    Char b='b';      
    System.out.println(Character.toLowerCase(a));   //输出"a"      
    System.out.println(Character.toUpperCase(b));   //输出"B"
}

输出结果:

aB

猜你喜欢

转载自blog.csdn.net/HouGOD/article/details/123108301
今日推荐