java字符串拆分、转换成数组

public class StringTest {
    public static void main(String[] args){
        String str1 = "ABCDEFG";
        String final1 = str1.substring(2,4);
        char final2 = str1.charAt(1);
        char final3 = str1.charAt(5);
        System.out.println(final1);
        System.out.println(final2);
        System.out.println(final3);

        String str = "A1B2C3D4E5F6G7H8";
        //将原字符串中的数字替换成无
        String final4 = str.replaceAll("\\d+","");
        //将原字符串中的字母替换成无
        String final5 = str.replaceAll("\\D+","");
        //新的纯字母字符串
        String[] str2 = new String[final4.length()];
        //新的纯数字字符串
        int[] num = new int[final5.length()];
        //将字符串转换成字符串数组
        for(int i=0; i

你可能感兴趣的:(java篇)