实现可以在 Arraylist 和 Integer 中存储任何级别的 ArrayList 的 ArrayList 的最佳方法是什么。
List<List<Integer>> list = ArrayList<List>();
仅允许列表中最多有 2 级列表,并且不允许混合使用 Interger 和 ArrayList。
这是 Python 中的一些简单的东西。它是一个愚蠢的数据结构,但不幸的是编码测试需要这些东西。
最佳答案
What is the best way of implementing an ArrayList that can store any level of ArrayLists within Arraylists and Integers
你唯一的选择List<Object>
如Generics are compile-time properties
。因此您无法根据运行时数据动态更改/决定类型。
所以,我认为最好也是唯一的选择List<Object>
。然而,you may need to cast many times
使用该列表。
关于java - Java 中的 ArrayList 内的 Arraylist 内的 Arraylist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55255022/