
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create a Dynamic 2D Array in Java
If you wish to create a dynamic 2d array in Java without using List. And only create a dynamic 2d array in Java with normal array then click the below link
You can achieve the same using List. See the below program. You can have any number of rows or columns.
Example
import java.util.ArrayList; import java.util.List; public class Tester { public static void main(String[] args) { List<int[]> rows = new ArrayList<>(); rows.add(new int[]{1,2,3}); rows.add(new int[]{1,2}); rows.add(new int[]{1}); //get element at row : 0, column : 0 System.out.println("[0][0] : " + rows.get(0)[0]); //get element at row : 1, column : 1 System.out.println("[1][1] : " + rows.get(1)[1]); } }
Output
[0][0] : 1 [1][1] : 2
Advertisements