Looks like this is what you want

    int columns = 2;
    int rows = 2;

    String[][] newArray = new String[columns][rows];
    newArray[0][0] = "France";
    newArray[0][1] = "Blue";

    newArray[1][0] = "Ireland";
    newArray[1][1] = "Green";

    for(int i = 0; i < rows; i++){
        for(int j = 0; j < columns; j++){
            System.out.println(newArray[i][j]);
        }
    }

Here I'll explain the code:

This declares the size of your new 2D array. In Java (and most programming languages), your first value starts at 0, so the size of this array is actually 2 rows by 2 columns

    int columns = 2;
    int rows = 2;

Here you are using the type String[][] to create a new 2D array with the size defined by [rows][columns].

    String[][] newArray = new String[columns][rows];

You assign the values by its placement within the array.

    newArray[0][0] = "France";
    newArray[0][1] = "Blue";

    newArray[1][0] = "Ireland";
    newArray[1][1] = "Green";

Looping through i would loop through the rows, and looping through j would loop through the columns. This code loops through all rows and columns and prints out the values in each index.

    for(int i = 0; i < rows; i++){
        for(int j = 0; j < columns; j++){
            System.out.println(newArray[i][j]);
        }
    }

Alternatively, assignment can be a one-liner:

    String[][] newArray = {{"France", "Blue"}, {"Ireland", "Green"}};

But I don't like this way, as when you start dealing with larger sets of data (like 10,000+ points of data with many columns), hardcoding it in like this can be rough.

Answer from theGreenCabbage on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional Arrays
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
Discussions

How do I populate a 2D String array with a String array created from a line of text from a .txt file?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
7
2
July 14, 2023
In Java, how do static arrays of Strings work? Strings are arrays of characters, so when the array of Strings is initialized with a given size, how does Java know how much memory to allocate?
It's really just an array of references (this means 32 or 64 bit addresses depending on the platform), no memory is allocated for the string objects. More on reddit.com
🌐 r/learnprogramming
9
1
December 16, 2022
Java Splitting a string into a 2d array
Why don't you just access the 1D array like a 2D array? index = x*width+y More on reddit.com
🌐 r/programminghelp
5
2
September 19, 2012
Two dimensional ArrayList, need help with constructor
There are probably better ways to solve your problem, but here is the answer to your question: List> list1 = new ArrayList>(); for (int i = 0; i < 10; i++) { List list2 = new ArrayList(); for (int j = 0; j < 10; j++) { list2.add(i * j); } list1.add(list2); } Integer value = list1.get(1).get(5); More on reddit.com
🌐 r/java
5
0
February 17, 2012
🌐
Runestone Academy
runestone.academy › ns › books › published › csjava › Unit9-2DArray › a2dSummary.html
9.3. 2D Arrays Summary — CS Java
Initialize a 2d array of integers named nums so that it has 1,2,3 in the first row and 4,5,6 in the second row. ... Initialize a 2d String array named list1 so that it has a,b,c in the first row and d,e,f in the second row.
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
A 2D array represents data in rows and columns. It can be understood as an array of 1D arrays. ... A 2-D array can be seen as a table with 'x' rows and 'y' columns where the row number ranges from 0 to (x-1) and column number ranges from 0 to ...
Published   May 4, 2026
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
2D arrays are declared by defining a data type followed by two sets of square brackets. ... In Java, when accessing the element from a 2D array using arr[first][second], the first index can be thought of as the desired row, and the second index ...
🌐
Coderanch
coderanch.com › t › 754467 › java › array-list-strings-array-strings
From array list of strings to a 2d array of strings (Beginning Java forum at Coderanch)
"Today it is Thursday.After 132 days,it will be" ??? wed / sun / mon / thurs --> incomplete javacode ... Assign a value to a numeric variable, then manipulate it, and return a new string. Read tab separated file and store on two dimensional arraylist
🌐
Ruby-Doc.org
ruby-doc.org › home › two dimensional array in java – the ultimate guide with examples
Two Dimensional Array in Java - The Ultimate Guide with Examples - Ruby-Doc.org
April 10, 2026 - javaCopyEditint[][] numbers; // Declaring a 2D array of integers String[][] names; // Declaring a 2D array of Strings double[][] grades; // Declaring a 2D array of doubles
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java array › print a java 2d array
Print a Java 2D Array | Baeldung
August 23, 2024 - It generates a new string representation of each row, which might be less efficient in terms of space complexity for arrays with a large number of columns. We lack control over how the array is formatted, and it depends on the implementation of the toString method of the elements. ... It’s important to note that all these approaches have a time complexity of O(m * n) because to print the entire 2D array, we must visit each element at least once.
🌐
ScienceDirect
sciencedirect.com › topics › computer-science › two-dimensional-array
Two-Dimensional Array - an overview | ScienceDirect Topics
A Java compiler written in C, for example, would probably use row pointers to store the character-string representations of the 51 Java keywords and word-like literals. This data structure would use 51 × 4 = 204 bytes for the pointers, plus 343 bytes for the keywords, for a total of 547 bytes (548 when aligned). Since the longest keyword (synchronized) requires 13 bytes (including space for the terminating NUL), a contiguous two-dimensional array would consume 51 × 13 = 663 bytes (664 when aligned).
🌐
w3resource
w3resource.com › java-exercises › basic › java-basic-exercise-155.php
Java - Change the rows and columns of a 2-dimension array
February 2, 2026 - Original Array: 10 20 30 40 50 60 After changing the rows and columns of the said array:10 40 20 50 30 60 ... import java.util.Scanner; public class Solution { public static void main(String[] args) { // Initializing a 2D array with values int[][] twodm = { {10, 20, 30}, {40, 50, 60} }; // Displaying the original array System.out.print("Original Array:\n"); print_array(twodm); // Performing transpose operation on the array System.out.print("After changing the rows and columns of the said array:"); transpose(twodm); } // Method to transpose the given 2D array private static void transpose(int[]
🌐
Coding Rooms
codingrooms.com › blog › iterating-through-2d-array-java
Iterating Through 2D Array Java
October 5, 2020 - Now let’s jump into nested for loops as a method for iterating through 2D arrays. A nested for loop is one for loop inside another. Take a look below to see what this means. package exlcode; public class Iteration2DExample { public static int[][] exampleVariableOne = {{0, 1, 2, 3, 4}, {4, 5, 6, 7, 8}}; public static void main(String[] args) { // nested for loops are necessary for // iterating through a 2D array for (int countOne = 0; countOne < exampleVariableOne.length; countOne++) { for (int countTwo = 0; countTwo < exampleVariableOne[countOne].length; countTwo++) { System.out.print("Index [" + countOne + "][" + countTwo + "]: "); System.out.println(exampleVariableOne[countOne][countTwo]); } } } }
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
JavaScript arrays are not associative arrays and so, array elements cannot be accessed using arbitrary strings as indexes, but must be accessed using nonnegative integers (or their respective string form) as indexes.
🌐
Tutorial Gateway
tutorialgateway.org › two-dimensional-array-in-java
Two Dimensional Array in Java
March 23, 2025 - Two Dimensional Array in Java means Array of Arrays. Java 2d Array or Two Dimensional Array, data stored in rows, columns & to access use index.
🌐
Medium
medium.com › @iamprem021 › a-simple-guide-to-2d-arrays-in-java-4f5f5e5e1a96
A Simple Guide to 2D Arrays in Java | by premprakash | Medium
May 24, 2024 - A Simple Guide to 2D Arrays in Java Arrays are a fundamental part of Java programming. While one-dimensional arrays are common, sometimes we need something more complex, like two-dimensional (2D) …
🌐
GeeksforGeeks
geeksforgeeks.org › java › print-2-d-array-matrix-java
Print a 2D Array or Matrix in Java - GeeksforGeeks
March 24, 2025 - Example 4: Using Arrays.deepToString(int[][]) converts the 2D array to a string in a single step. ... // Java program to print the elements of // a 2 D array or matrix using deepToString() import java.io.*; import java.util.*; class Geeks { public static void print2D(int mat[][]) { System.out.println(Arrays.deepToString(mat)); } public static void main(String args[]) throws IOException { int mat[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }; print2D(mat); } }
🌐
W3Schools
w3schools.com › java › java_arrays.asp
Java Arrays
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array, define the variable type with square brackets [ ] : ... We have now declared a variable that holds an array of strings.
🌐
FavTutor
favtutor.com › blogs › print-2d-array-in-java
Print a 2D Array or Matrix in Java: 4 Easy Methods (with code)
June 16, 2023 - Find out how to print a 2D Array in Java using various methods with code. This can be used for both 2D and 3D Matrix.
🌐
Dremendo
dremendo.com › java-programming-tutorial › java-two-dimensional-array
Two Dimensional Array in Java Programming | Dremendo
We can also store as well as access the numbers in a 2D array using either for, while or do while loop. Let's see a few examples. Program to input numbers in a 3x3 Matrix and display the numbers in a table format. import java.util.Scanner; public class Example { public static void main(String args[]) { int a[][]=new int[3][3]; Scanner sc=new Scanner(System.in); int r,c; System.out.println("Enter 9 numbers"); for(r=0; r<3; r++) { for(c=0; c<3; c++) { a[r][c]=sc.nextInt(); } } System.out.println("\nOutput"); for(r=0; r<3; r++) // this loop is for row { for(c=0; c<3; c++) // this loop will print 3 numbers in each row { System.out.print(a[r][c]+" "); } System.out.println(); // break the line after printing the numbers in a row } } }
🌐
Educative
educative.io › answers › how-to-use-2-d-arrays-in-java
How to use 2-D arrays in Java
Similar to a 1-D array, a 2-D array is a collection of data cells. 2-D arrays work in the same way as 1-D arrays in most ways; however, unlike 1-D arrays, they allow you to specify both a column index and a row index.