But I thought I had done this before where I could do something like:
Can this be done in some way? I am ultimately trying to make a 3 dimensional ArrayList, but I am having trouble with just the first dimension.
I could have sworn I had done this before. Everything I am finding on google is showing the need to add elements individually with .add().
Thank you for any help.
6: Slightly different version with a Stream. List<Integer> numbers = IntStream.of(1, 2, 3, 4, 5).boxed().collect(Collectors.toList()); Again, please read the link. Options 5 and 6 have the advantage that (at least with the present implementation) the runtime type of the value returned is java.util.ArrayList.
Please declare your List as List<XYZ> not ArrayList<XYZ>.
Steve Skavnicky wrote:The documentation seems to mention this will make the list "unmodifiable".
I was wanting to keep things mutable.
That is what I was hoping you would find. Options 2 4 5 6 create an ArrayList which is mutable after ceation.
. . . . This is a lost cause.
What makes you think that? I have given you six suggestions which will do what you were asking for.
By the way: there is no such thing as a 3D list. There is however such a thing as a List<List<List<XYZ>>>. What would you want such a complicated data structure for?