[java] I don't know how to put an array in an array list.

Asked 2 years ago, Updated 2 years ago, 135 views

I want to know how to put an array in the Java arrayList.

[] The square brackets are arraylist {} Braces are arrays

[{array 0, array 1, array2} {array 0, array 1, array2}...{array0,array1,array2}]

I want to use it like this.

The array is int num[] = new int[3]. Assuming that the name of the arrayList is numlist, I would appreciate it if you let me know.

java arraylist

2022-09-22 21:13

1 Answers

Are you talking about this?

public static void main(String[] args){
        int[] nums = new int[3];

        // arraylist for storing arrays
        ArrayList<int[]> mylist = new ArrayList<int[]>();;
        mylist.add(nums);
}

When declaring an array list, you can specify the type like ArrayList.


2022-09-22 21:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.