Day39--返回大写字母的字符串

Day39--返回大写字母的字符串

使用String类的toUpperCase()方法

示例代码如下:

public class Main {
    public static void main(String[] args) {
        String str = "hello";
        String upperCaseStr = str.toUpperCase();
        System.out.println(upperCaseStr);
    }
}
  • 这种方法直接在原始字符串对象上调用toUpperCase(),它会返回一个新的字符串,新字符串中的所有字符都是大写形式,而原始字符串不会被改变。
posted @ 2024-11-25 21:48  1hahahahahahahaha  阅读(15)  评论(0)    收藏  举报