0
A simple question
Trying to figure out. s.split("\\s+"); What does split do. And what is \\s+ Plis help me
2 ответов
+ 1
s is a line of string which may have spaces, so splitting with split function with delimiter results into a strings of array..
There \\s+ for delimiter for space (1 or more in sequence) so split result into words..
Ex : s = "hi hello SoloLearn platform"
String a[] = s.split("\\s+");
Now array a have values
a[0] = "hi" ;
a[1] = "hello" ;
a[2] = "SoloLearn" ;
a[3] = "platform" ;
Hope it helps...
0
split cuts string to array
\\s+ take space one or more as delimiter
import java.util.*;
...
String s = "a b c d e f g h";
String[] as = s.split("\\s+");
System.out.println(Arrays.toString(as) );