java 中字符串有一个方法是split()。之前知道的用法是,字符串中有特殊的字符的话,可以做为分隔符,把字符串分隔为数组。 例如:
String address="1@2@3@4";
String[] splitAddress=address.split("@");
但是今天发现一种用法,如下:
public class Test1 { public static void main(String[] args) { String identityCode = "243434254575767675"; String[] tempA = identityCode.split("|"); for (int i=0;i < tempA.length;i++) { System.out.println(tempA[i]); } } }
打印的结果如下:
6
7
6
7
5
5
问题:貌似只有这个符号可以这么用,现在还没有能知道是为什么,还会继续看一下这个。如果有哪位大佬知道,可以在评论里告知一下,谢谢~