Reputation: 25
I have 3 arrays of integer for example:
int[] l1 = {1,2,3};
int[] l2 = {4,5,6};
int[] l3 = {7,8,9};
and I have an integer witch shows me a number between 1 to 3 , I want know how to relate this number to arrays I mean if it was 2 then chose the second array to work with
Upvotes: 0
Views: 35
Reputation: 1625
You can use 2D-Array to do that;
import java.util.Arrays;
public class Solution {
public static void main(String[] args) {
int choice = 2;
int[] l1 = {1,2,3};
int[] l2 = {4,5,6};
int[] l3 = {7,8,9};
int[][] toChoose = new int[3][];
toChoose[0] = l1;
toChoose[1] = l2;
toChoose[2] = l3;
System.out.println(Arrays.toString(toChoose[1]));
}
}
Upvotes: 0
Reputation: 361
If I understood you correctly, one option might be to have a multidimensional array along the following lines:
int[][] array = {{1,2,3}, {4,5,6}, {7,8,9}};
int[] subArray = array[2];
System.out.println(Arrays.toString(subArray));
Upvotes: 1