我想在 Java 中的 C++ 中创建这样的 vector 数组
vector<int> tab_u[255]
我不知道如何快速创建。我试试这个:
List<Integer> tab[] = new List[255];
但我无法添加一些东西
我想要这样的东西
tab[0] = {1,2,2,3}
tab[1] = {2,3}
tab[2] = {1}
最佳答案
List<Integer>[] myListArray = new List<>[255];
现在您有了可以包含Integer
类型的List
的Array
。
但里面什么也没有。
因此,要填充它,您需要首先创建列表,然后将它们放入数组中。
List<Integer> firstList = new ArrayList<>(); // List itself can't be instantiated, it's abstract
myListArray[0] = firstList; // there you add the 1st element in your array to be the list you just created
然后您可以填写您的列表
myListArray[0].add(1);
你可以用一些俏皮话“更快”地写出所有这些内容,但老实说我不会推荐它(不可读)。
仅供引用:还建议像这样定义数组:
int[] myIntegerArray;
而不是C
-Way
int myIntegerArray[];
更容易阅读:“int - array - myIntegerArray”(C-Way 将读取“int - myIntegerArray - array”)
关于java - 如何在java中创建列表数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57885366/