您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
在Java中,可以使用String
类的toLowerCase()
和toUpperCase()
方法来实现字符串的大小写转换。以下是示例代码:
public class Main {
public static void main(String[] args) {
String str = "Hello World!";
// 转换为小写
String lowerCaseStr = str.toLowerCase();
System.out.println(lowerCaseStr); // 输出: hello world!
// 转换为大写
String upperCaseStr = str.toUpperCase();
System.out.println(upperCaseStr); // 输出: HELLO WORLD!
}
}
在这个示例中,我们首先定义了一个字符串str
,然后使用toLowerCase()
方法将其转换为小写,并将结果存储在lowerCaseStr
变量中。接着,我们使用toUpperCase()
方法将原始字符串转换为大写,并将结果存储在upperCaseStr
变量中。最后,我们分别输出这两个转换后的字符串。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
开发者交流群:
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。