话不多说直接上代码:
java 中以||作为split分隔符正确的写法需要将||进行转义,否则可能得不到正确的结果,在java中单竖线需要转义,就意味着需要将双竖线都转义,
public static void main(String[] args) {
//偏强,偏弱,一般,偏弱,偏弱,一般,弱,偏弱||数理智能,语言智能,空间智能,身体智能,音乐智能,人际智能,自然智能,内省智能
String code ="偏强,偏弱,一般,偏弱,偏弱,一般,弱,偏000000||数理智能,语言智能,空间智能,身体智能,音乐智能,人际智能,自然智能,内省智能";
String[] split = code.split("\\|");
String[] split1 = split[0].split(",");
System.out.println(split[0]);
System.out.println(Arrays.toString(split1));
System.out.println(split1[0]);
System.out.println(split1[7]);
}