+ 2
need help in understanding this line: String[] digits = number.split("(?<=.)");
I wanna know exactly the meaning of this ("(?<=.)"). I encountered that line upon browsing for an algorithm in splitting an integer into digits. Thanks!
3 Antworten
+ 3
Here is a good stackoverflow thread that might help you,
https://stackoverflow.com/questions/5235401/split-string-into-array-of-character-strings
+ 2
regex (?<=X) is positive lookbehind, mean place where (X) is before target position
if X is . char , it is place after (each) char
+ 2
You just need a split("") since java 8
In java 1.7 or less you had to do split("\\B")
to make sure not consider the first empty character matched.