The user will input a value between 1 and 5. Base on the input value, I would like to create multiple arraylist with different names.
Example 1 (when input = 3) :
ArrayList<String> Group0 = new ArrayList<>();
ArrayList<String> Group1 = new ArrayList<>();
ArrayList<String> Group2 = new ArrayList<>();
Example 2 (when input = 5) :
ArrayList<String> Group0 = new ArrayList<>();
ArrayList<String> Group1 = new ArrayList<>();
ArrayList<String> Group2 = new ArrayList<>();
ArrayList<String> Group3 = new ArrayList<>();
ArrayList<String> Group4 = new ArrayList<>();
I apologise beforehand if this question seem trivial. I am relatively new to coding and thus would be very grateful to anyone who might know of an available method/command to get the above results. Thankyou!
I have tried to do it this way but i cant seem to use "label" when initialising arraylist. The error states "variable label is already defined in method main(String[]).
public static void main(String[] args) {
int userInput = 3;
int count = 0;
while(count < (userInput)) {
String label = "Group" + Integer.toString(count);
ArrayList<String> label = new ArrayList<>();
count++;
}
}