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.
method1because main method looks tidier. Also, I may not need to createString[] arr, I will create aStringand do the process on it.split()result in a new variable, because it work withregexp, andregexpis so slow.