+ 1

Java

What is split(“\\s+”) in java

9th Nov 2019, 5:27 PM
Omar Kammoun
Omar Kammoun - avatar
4 Answers
+ 3
split("\\s"); using this it splits your string on the basis of whitespace in your string. Simple code : String s = "hi sololearn lol"; String[] spl= s.split("\\s"); For(String x : spl) { System.out.println(x); } Outputs: Hi Sololearn Lol
9th Nov 2019, 5:33 PM
Chirag Kumar
Chirag Kumar - avatar
+ 1
hi thank you but why we use two // instead of one ? to split more than one space?
9th Nov 2019, 5:39 PM
Omar Kammoun
Omar Kammoun - avatar
0
ohh nice thank you
9th Nov 2019, 7:32 PM
Omar Kammoun
Omar Kammoun - avatar