This is my initial code,
public class Main {
public static void main(String[] args) {
// --------Declaring variables--------
int arrLength = 6;
String[] arr1 = new String[arrLength];
String[] arr2 = new String[arrLength];
String[] arr3 = new String[arrLength];
joinArrays(arr1,arr2,arr3);
}
private static void joinArrays(String[] arr1, String[] arr2, String[] arr3){
System.out.print("Array 1 : ");
System.out.println(String.join(",",arr1));
System.out.println("");
System.out.print("Array 2 : ");
System.out.println(String.join(",",arr2));
System.out.println("");
System.out.print("Array 3 : ");
System.out.println(String.join(",",arr3));
System.out.println("");
}
But i need to do this in a loop (without using so much print methods). I tried below way, but it only print out
Array 1 : arr1
Array 2 : arr2
likewise, it doesn't join the list that passed to the parameter.
private static void joinArrays(String[] arr1, String[] arr2, String[] arr3){
for(int i = 0; i<3;i++){
System.out.print("Array "+i+" : ");
System.out.println(String.join(",","arr"+i));
System.out.println("");
}
}
How can i do this looping thing easy.