I believe there are many similar questions, sorry if this is too common. I want to learn which one is better/faster/space efficient etc and why.
public static void(String[] main){
//case 1
String[] str_arr = new String[n];
method1(str_arr)
//case 2
String[] str_arr = new String[n];
String[] arr = new String[n];
for(int i=0; i < n; i++){
arr[i] = str_arr[i].split("some_char")[2];
}
method2(arr);
}
void method1(String[] str_arr){
String[] arr = new String[n];
for(int i=0; i < n; i++){
arr[i] = str_arr[i].split("aChar")[2];//assume there are 50 of aChar
}
// do_something with arr ;
}
void method2(String[] arr){
// do_something with arr ;
}
Which one should I prefer?
Thanks in advance.