I have a
String data =
-rw-rw-r--+ 1 aime1 svrtech 83338 Apr 2 10:26 sat.log -rw-rw-r--+ 1 aime1 svrtech 2435 Apr 2 10:48 MAT.log -rw-rw-r--+ 1 aime1 svrtech 3470 Apr 2 08:35 ant_build.log
I want to split this as following and want to store in ArrayList
-rw-rw-r--+ 1 aime1 svrtech 83338 Apr 2 10:26 sat.log
-rw-rw-r--+ 1 aime1 svrtech 2435 Apr 2 10:48 MAT.log
-rw-rw-r--+ 1 aime1 svrtech 3470 Apr 2 08:35 ant_build.log
I thought of using split function. How do i split on 7th space. Anyone having idea how to do that.
String#split takes the regex as the arguments,so try with something like this
String data ="-rw-rw-r--+ 1 aime1 svrtech 83338 Apr 2 10:26 sat.log -rw-rw-r--+ 1 aime1 svrtech 2435 Apr 2 10:48 MAT.log -rw-rw-r--+ 1 aime1 svrtech 3470 Apr 2 08:35 ant_build.log";
String arr[]=data.split("(?<=.log )");
for(String s:arr){
System.out.println(s);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With