You must use split("\\|") . You need to break the special meaning of regex | . You do this with \\| . [Note that split() splits according to regex].
String s = "1|2|8|11|4|5|6|14|15|16|13|17|7|9|12|10"; String[] arr = s.split("\\|"); System.out.println(Arrays.toString(arr));
leads to:
[1, 2, 8, 11, 4, 5, 6, 14, 15, 16, 13, 17, 7, 9, 12, 10]
source share