How exactly does String.split() method in Java work when regex is provided?
问题 I\'m preparing for OCPJP exam and I ran into the following example: class Test { public static void main(String args[]) { String test = \"I am preparing for OCPJP\"; String[] tokens = test.split(\"\\\\S\"); System.out.println(tokens.length); } } This code prints 16. I was expecting something like no_of_characters + 1. Can someone explain me, what does the split() method actually do in this case? I just don\'t get it... 回答1: It splits on every "\\S" which in regex engine represents \S non