Transformation functionality for the String class

String类的转换功能:
package com.itheima_05;
/*
 * String类的转换功能:
 * char[] toCharArray():把字符串转换为字符数组
 * String toLowerCase():把字符串转换为小写字符串
 * String toUpperCase():把字符串转换为大写字符串
 * 
 * 字符串的遍历:
 *         A:length()加上charAt()
 *         B:把字符串转换为字符数组,然后遍历数组
 */
public class StringDemo {
    public static void main(String[] args) {
        //创建字符串对象
        String s = "abcde";
        
        //char[] toCharArray():把字符串转换为字符数组
        char[] chs = s.toCharArray();
        for(int x=0; x<chs.length; x++) {
            System.out.println(chs[x]);
        }
        System.out.println("-----------");
        
        //String toLowerCase():把字符串转换为小写字符串
        System.out.println("HelloWorld".toLowerCase());
        //String toUpperCase():把字符串转换为大写字符串
        System.out.println("HelloWorld".toUpperCase());
    }
}

 数组里面的长度是属性。String类里面的长度是方法。

原文地址:https://www.cnblogs.com/lzp123456-/p/9741957.html