string类的学习

package com.te.jdkapi;

import java.util.Arrays;

public class StringDemo {
    public static void main(String[] args) {
        String name = new String("caihengaiaikjkj");
        String name2 = new String("CAIHENG");
        System.out.println(name.equalsIgnoreCase(name2));
        System.out.println(name.length());
        System.out.println(name.substring(3));//截取从3以后的字符串
        System.out.println(name.substring(1,3));//截取从1到3的字符串
        System.out.println(name.charAt(1)); // 获取索引为1的字符
        System.out.println(name.indexOf("ai"));// 获取字符串第一次出现的下表
        System.out.println(name.lastIndexOf("ai"));// 从最后开始最开始出现的下表
        System.out.println(name.replace("ai","ok"));//替换
        String[] arr = name.split("a"); // 以什么分割字符串
        System.out.println(Arrays.toString(arr));

    }
}
posted @ 2022-11-03 12:59  竹石2020  阅读(13)  评论(0编辑  收藏  举报