您当前的位置: 首页 >  Java

哆啦A梦_i

暂无认证

  • 0浏览

    0关注

    629博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Java:转换大小写 (toLowerCase()和toUpperCase())

哆啦A梦_i 发布时间:2019-05-11 17:27:05 ,浏览量:0

String 类

.toLowerCase() 方法:将字符串中的所有字符全部转换成小写,非字母的字符不受影响。

语法格式如下:

字符串名.toLowerCase() 

.toUpperCase() 方法:将字符串中的所有字符全部转换成大写,非字母的字符不受影响。

语法格式如下:

字符串名.toUpperCase()

例如:

  1. String str="abcDef 哦哦ghijkLMn";
  2. System.out.println(str.toLowerCase()); //输出:abcdef 哦哦 ghijklmn
  3. System.out.println(str.toUpperCase()); //输出:ABCDEF 哦哦GHIJKLMN

例 1

下面的实例代码演示:如何对字符串应用大写和小写转换。

  1. public static void main(String[] args)
  2. {
  3. String en="The Day You Went Away"; //定义原始字符串
  4. System.out.println("原始字符串:"+en);
  5. System.out.println("使用 toLowerCase() 方法之后为:"+en.toLowerCase());
  6. System.out.println("使用 toUpperCase() 方法之后为:"+en.toUpperCase());
  7.  
  8. en="select id,name,sex,address,birthday from students";
  9. System.out.println("原始字符串:"+en); //定义原始字符串
  10. System.out.println("使用 toLowerCase() 方法之后为:"+en.toLowerCase());
  11. System.out.println("使用 toUpperCase() 方法之后为:"+en.toUpperCase());
  12. }

运行结果如下:

原始字符串:The Day You Went Away

使用 toLowerCase() 方法之后为:the day you went away

使用 toUpperCase() 方法之后为:THE DAY YOU WENT AWAY

关注
打赏
1556978864
查看更多评论
立即登录/注册

微信扫码登录

0.0382s