Skip to content

Tag: arraylist

Create a list of List from an Array

How can i create a list of List from Array eg: int[] arr = {3, 1, 5, 8, 2, 4}. Such that the lists in the List have only two elements eg: [[3,1], [5,8], [2,4]]. So far i have tried code below but it return only lists with one element,I can’t figure out where i went wrong. Result: [[3], [1],

java arraylist.add overwriting

I tried to add 1D ArrayList into 2D ArrayList like the following code, but the output was [34, 35, 36] [[34, 35, 36]] [4, 5, 6] [[4, 5, 6], [4, 5, 6]] <- the correct output would be [[34, 35, 36], [4, 5, 6]]. the previous one was overwritted, how can I solve this problem? Answer You put the array

Print a string from ArrayList of String[] per Index?

How to print ArrayList of String[] into String per index with expected Output like this Here is the code and how to print it? Answer You were pretty close to it: This generates your String to be outputted. Printing: Just don’t forget to initialize yourArrayList prior of the method call.