如何从列表中的列表中取出一个元素
How can I take out the an element from a list in a list
我正在编写 java 代码,在这里我想知道如何从列表中的列表中取出元素,我知道存储的列表的索引。
我知道你不会理解这个,所以这是代码。
public static List<ArrayList> dnList = new ArrayList<>();
public static ArrayList<Integer> dm1n = new ArrayList<>();
public static ArrayList<Integer> dm2n = new ArrayList<>();
public static ArrayList<Integer> dm3n = new ArrayList<>();
public static ArrayList<Integer> dm4n = new ArrayList<>();
public static ArrayList<Integer> dm5n = new ArrayList<>();
public static ArrayList<Integer> dm6n = new ArrayList<>();
public static ArrayList<Integer> dm7n = new ArrayList<>();
public static ArrayList<Integer> dm8n = new ArrayList<>();
public static ArrayList<Integer> dm9n = new ArrayList<>();
public static ArrayList<Integer> dm10n = new ArrayList<>();
So here the first list you have contains all other lists.
现在我有一个变量 ln,它包含我想要的元素所在的 dnList 的索引和另一个
包含实际列表索引的变量索引。
Note : The element I want is actually in one of the list from dm1n to dm10n and they all are stored in dnList. Variable ln contain a index in dnList and variable index contain a index in the actual list.
我试过了 -
int element = dnList.get(ln).get(index)
但它没有用,所以我想要别的东西。
提前致谢。
尝试
int element = (Integer)(dnList.get(ln)).get(index);
我正在编写 java 代码,在这里我想知道如何从列表中的列表中取出元素,我知道存储的列表的索引。 我知道你不会理解这个,所以这是代码。
public static List<ArrayList> dnList = new ArrayList<>();
public static ArrayList<Integer> dm1n = new ArrayList<>();
public static ArrayList<Integer> dm2n = new ArrayList<>();
public static ArrayList<Integer> dm3n = new ArrayList<>();
public static ArrayList<Integer> dm4n = new ArrayList<>();
public static ArrayList<Integer> dm5n = new ArrayList<>();
public static ArrayList<Integer> dm6n = new ArrayList<>();
public static ArrayList<Integer> dm7n = new ArrayList<>();
public static ArrayList<Integer> dm8n = new ArrayList<>();
public static ArrayList<Integer> dm9n = new ArrayList<>();
public static ArrayList<Integer> dm10n = new ArrayList<>();
So here the first list you have contains all other lists.
现在我有一个变量 ln,它包含我想要的元素所在的 dnList 的索引和另一个 包含实际列表索引的变量索引。
Note : The element I want is actually in one of the list from dm1n to dm10n and they all are stored in dnList. Variable ln contain a index in dnList and variable index contain a index in the actual list.
我试过了 -
int element = dnList.get(ln).get(index)
但它没有用,所以我想要别的东西。 提前致谢。
尝试
int element = (Integer)(dnList.get(ln)).get(index);