+ 9

Splitting a string

/*I can seem to understand whats happening inside the str.split method as" \n" dosent seem to be doing anything..*/ public class Program { public static void main(String[] args) { String str = "abc def ghi" ; String[] strArr = str.split("\n"); //<<<here for(int x = 0; x < strArr.length;++x){ System.out.print(strArr[x]); } } }

1st Oct 2017, 10:27 AM
D_Stark
D_Stark - avatar
5 odpowiedzi
+ 11
Because \n is character for new line and you have just one line String.
1st Oct 2017, 10:42 AM
Vukan
Vukan - avatar
+ 6
does it treat it like a space similer to this> " " then?
1st Oct 2017, 10:44 AM
D_Stark
D_Stark - avatar
+ 2
Yep
1st Oct 2017, 11:38 AM
Maksym Zieliński
Maksym Zieliński - avatar
+ 1
Use \s
6th Oct 2017, 7:45 AM
Khoibam Praveen
Khoibam Praveen - avatar