About 164,000 results
Open links in new tab
  1. Different Ways To Declare And Initialize 2-D Array in Java

    Nov 13, 2024 · When you initialize a 2D array, you must always specify the first dimension(no. of rows), but providing the second dimension(no. of columns) may be omitted. Java compiler is smart enough to manipulate the size by checking the number of elements inside the columns.

  2. Initialising a multidimensional array in Java - Stack Overflow

    Dec 4, 2013 · String[][] myStringArray = new String [x][y]; is the correct way to initialise a rectangular multidimensional array. If you want it to be jagged (each sub-array potentially has a different length) then you can use code similar to this answer.

  3. Syntax for creating a two-dimensional array in Java

    Jan 17, 2021 · You can initialize this array at compile time like below: int[][] multD = {{2, 4, 1}, {6, 8}, {7, 3, 6, 5, 1}}; You can easily iterate all elements in your array:

  4. Java Multi-Dimensional Arrays - GeeksforGeeks

    Apr 23, 2025 · Two-Dimensional Array (2D-Array) Two-dimensional array is the simplest form of a multidimensional array. A 2-D array can be seen as an array storing multiple 1-D array for easier understanding. Syntax (Declare, Initialize and Assigning) // Declaring and Intializing data_type[][] array_name = new data_type[x][y]; // Assigning Value

  5. Declare and initialize two-dimensional arrays in Java

    Oct 12, 2023 · To initialize a two-dimensional array of characters, we can use the String.toCharArray() method in Java. This method converts the given string into a sequence of characters and returns a newly created character array.

  6. Initializing Arrays in Java - Baeldung

    Dec 16, 2024 · In this article, we explored different ways of initializing arrays in Java. Also, we learned how to declare and allocate memory to arrays of any type, including one-dimensional and multi-dimensional arrays.

  7. How to Initialize an Array in Java? - GeeksforGeeks

    Apr 14, 2025 · In this article, we will discuss different ways to declare and initialize an array in Java. Understanding how to declare an array in Java is very important. In Java, an array is declared by specifying its data type, and an identifier, and adding brackets [] …

  8. Initialize 2D array in Java - Java2Blog

    Jan 11, 2021 · There are several ways to create and initialize a 2D array in Java. Let’s see some examples. Initialize 2D array Using for loop. This is the simplest approach in which we create an array and initialize every index using for loop. Output: Initialize 2D array using an initializer.

  9. java - Initialize 2D array - Stack Overflow

    Dec 12, 2012 · If it is to simply initialize a 2D array to values 0-9, it would be much easier to just define, declare and initialize within the same statement like this: private char[][] table = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}};

  10. Mastering Java Multidimensional Arrays: A Comprehensive Guide

    Apr 7, 2025 · Explore the intricacies of Java's multidimensional arrays with our in-depth guide. Learn how to declare, initialize, and utilize arrays of arrays to manage complex data structures effectively. TNS OK SUBSCRIBE Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important ...

  11. Some results have been removed
Refresh