Question: Java Convert a 2D array to a 2D ArrayList. Here is a 2D int array: int[][] nums1 = {{1, 2, 3, 4}, {5, 6, 7,

Java Convert a 2D array to a 2D ArrayList.

Here is a 2D int array: int[][] nums1 = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12, 13}, {14, 15}};

He is another 2D int array: int[][] nums2 = {{3,3,3,3,3},{3,7,3,3,7,7,7,7,3},{3,3,3,3,9}};

Write a method that converts both these 2D arrays to a 2D ArrayList where if a value in the 2D array is a 7, create a new ArrayList in the 2d Arraylist. Each new array created after the first one has to start with a 7. The method has to return a 2D ArrayList.

Here is the output for the two int 2D arrays.

nums1: [1,2,3,4] , [7, 5 ,6], [7,8] , [7, 9,10,11,12,13] , [7, 14,15];

nums2 = [3,3,3,3,3], [7,3] , [7] , [7] , [7] , [7] , [7, 3] , [7,3,3,3,3,9];

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!