[Solved] How to make a 2d array in JAVA?


If you could please point me towards some reading material that can teach me how to add, remove, get and iterate over the elements of the method suggested by you.

Arrays don’t support those operations. To add and remove elements you really need to use a List such as ArrayList.

List<List<Integer>> list2d = new ArrayList<>();
// add a row
list2d.add(new ArrayList<>());
// add an element
list2d.get(0).add(1);

Note: if you wish to lookup by date you can use a Map of LocalDate such as

Map<LocalDate, List<Double>> dateToDoubleList = new HashMap<>();

There are a number of 3rd party libraries which support List<double> more efficiently. an ArrayList<Double> can use 28 bytes per element and a LinkedlIst can use 48 bytes per entry. If you use a collection which wraps primitives (or write your own) it might only use 8 bytes per double.

5

solved How to make a 2d array in JAVA?