- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to 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
- Related Articles
- How to create a dynamic 2D array inside a class in C++
- How to store a 2d Array in another 2d Array in java?
- how to initialize a dynamic array in java?
- how to shuffle a 2D array in java correctly?
- Memorization (1D, 2D and 3D) Dynamic Programming in Java
- How to read a 2d array from a file in java?
- How to create a dynamic array of integers in C++ using the new keyword
- Print a 2D Array or Matrix in Java
- How to initialize a dynamic array in C++?
- How to sort a 2D array in TypeScript?
- How to get rows and columns of 2D array in Java?
- How to create a generic array in java?
- How to create a dynamic search box in ReactJS?
- How to populate a 2d array with random alphabetic values from a range in Java?
- How to convert a 2D array into 1D array in C#?

Advertisements