I am not sure I am following, but you might be looking for a Map<Integer,String>. or Map<Integer,List<String>>. [have a look on List, and HashMap]

Map allows association of the key [Integer] to the value [String or List].

Map also allows fast lookup of key, and its attached value.

(*) You should use Map<Integer,List<String>> if you want to attach more then one String per Integer, or alternatively you can use apache commons MultiMap

Answer from amit on Stack Overflow
🌐
Sololearn
sololearn.com › en › Discuss › 1803904 › 2d-array-with-different-data-types-java
2D array with different data types? (Java)
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
W3Schools
w3schools.com › java › java_arrays_multi.asp
Java Multi-Dimensional 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 ... A multidimensional array is an array that contains other arrays.
🌐
Blogger
javarevisited.blogspot.com › 2016 › 02 › 6-example-to-declare-two-dimensional-array-in-java.html
6 ways to declare and initialize a two-dimensional (2D) String and Integer Array in Java - Example Tutorial
June 28, 2025 - In Java, you can declare a 2D array with just one dimension but that has to be the first dimension. Leaving both dimension or first dimension while declaring an array is illegal in Java and throw a compile-time error as shown below:
🌐
Sololearn
sololearn.com › en › Discuss › 216351 › how-can-i-make-2d-array-with-different-data-type
How Can I make 2D array with different data type?
Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Codecademy
codecademy.com › learn › learn-java › modules › java-two-dimensional-arrays › cheatsheet
Learn Java: Two-Dimensional Arrays Cheatsheet | Codecademy
In Java, initializer lists can be used to quickly give initial values to 2D arrays. This can be done in two different ways. If the array has not been declared yet, a new array can be declared and initialized in the same step using curly brackets. If the array has already been declared, the new keyword along with the data type ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › multidimensional-arrays-in-java
Java Multi-Dimensional Arrays - GeeksforGeeks
A multi-dimensional array in Java is an array of arrays that allows data to be stored in tabular form such as rows and columns. It is commonly used to represent matrices, tables, and grids in programs.
Published   March 14, 2026
🌐
Java67
java67.com › 2014 › 10 › how-to-create-and-initialize-two-dimensional-array-java-example.html
How to declare and Initialize two dimensional Array in Java with Example | Java67
If you know how to create a one-dimensional array and the fact that multi-dimensional arrays are just an array of the array in Java, then creating a 2-dimensional array is very easy. Instead of one bracket, you will use two e.g. int[][] is a two-dimensional integer array. You can define a 2D array in Java as follows :
🌐
Software Testing Help
softwaretestinghelp.com › home › java › multidimensional arrays in java (2d and 3d arrays in java)
MultiDimensional Arrays In Java (2d and 3d Arrays In Java)
April 1, 2025 - Hence for the 2D array as well, rows come first and columns next. This was all about multi-dimensional arrays in Java. We have discussed all the aspects of two-dimensional arrays as well as an array with more than two dimensions.
🌐
Carnegie Mellon University
cs.cmu.edu › ~mrmiller › 15-110 › Handouts › arrays2D.pdf pdf
Two-Dimensional Arrays 15-110 Summer 2010 Margaret Reid-Miller
Similarity with 1D Arrays · • Each element in the 2D array must by the same type, • either a primitive type or object type. • Subscripted variables can be use just like a variable: ! rating[0][3] = 10;! • Array indices must be of type int and can be a · literal, variable, or expression. ...
🌐
HWS
math.hws.edu › eck › cs124 › javanotes8 › c7 › s5.html
Javanotes 8.1.3, Section 7.5 -- Two-dimensional Arrays
In a true 2D array, all the elements of the array occupy a continuous block of memory, but that's not true in Java. The syntax for array types is a clue: For any type BaseType, we should be able to form the type BaseType[], meaning "array of BaseType." If we use int[] as the base type, the type that we get is "int[][] meaning "array of int[]" or "array of array of int."
Top answer
1 of 2
1

It's slightly unclear what you're asking. In Java we don't actually have 2D arrays. Instead we have arrays of arrays. Similarly there is just 1D ArrayList which can contain different ArrayLists.

Another thing is the type stored. I would suggest writing your own class which would store the number Roman or Arabic.

public class RomanOrArabic {
    private Long arabic;
    private String roman;

    public boolean isArabic(){
        return arabic != null;
    }
    //add getters, smart setters, validators for String being Roman etc.
}

Then declare your ArrayList:

ArrayList<ArrayList<RomanOrArabic>> list = new ArrayList<>();
2 of 2
0

I saw there was some confusion so I thought I would post the solution here.

    // The solution
    Object RomanNumeralValues[][] = {
            {500000, 999999, 900000, "D\u0305", "C\u0305M\u0305"},
            {100000, 499999, 400000, "C\u0305", "C\u0305D\u0305"},
            {50000, 99999, 90000, "L\u0305", "X\u0305C\u0305"},
            {10000, 49999, 40000, "X\u0305", "X\u0305L\u0305"},
            {5000, 9999, 9000, "V\u0305", "MX\u0305"},
            {1000, 4999, 4000, "M", "MV\u0305"},
            {500, 999, 900, "D", "CM"},
            {100, 499, 400, "C", "CD"},
            {50, 99, 90, "L", "XC"},
            {10, 49, 40, "X", "XL"}
    };

    // Where the solution gets used
    String romanNumeral = "";
    for (Object rmRange[]: RomanNumeralValues) {
        romanNumeral += extractRomanNumeralsBelowOneMillion(
                (int)rmRange[0],
                (int)rmRange[1],
                (int)rmRange[2],
                rmRange[3].toString(),
                rmRange[4].toString()
        );
    }

I'm not comfortable with type casting just to pull the value out of an object array, but I guess it works. I'll leave the question open in case anyone has better solutions.

🌐
Programiz
programiz.com › java-programming › multidimensional-array
Java Multidimensional Array (2d and 3d Array)
Here is how we can initialize a 2-dimensional array in Java. ... As we can see, each element of the multidimensional array is an array itself. And also, unlike C/C++, each row of the multidimensional array in Java can be of different lengths. ... class MultidimensionalArray { public static ...
🌐
Quora
quora.com › Can-a-2D-array-contain-2-different-data-types
Can a 2D array contain 2 different data types? - Quora
Answer (1 of 2): This depends on the language and its type system. Generally, an array (2D or not) can only contain one datatype. But that datatype itself can be flexible of course.
🌐
freeCodeCamp
freecodecamp.org › news › 2d-array-in-java-two-dimensional-and-nested-arrays
2D Array in Java – Two-Dimensional and Nested Arrays
August 10, 2022 - A multidimensional array is simply an array of arrays. You can look it as a single container that stores multiple containers. In this article, we'll talk two dimensional arrays in Java.
🌐
Scaler
scaler.com › home › topics › two dimensional array in java
Two Dimensional Array In Java with Examples - Scaler Topics
June 8, 2024 - Here, the new DataType[r][c] statement creates a two dimensional array object that contains r rows and c columns and elements of DataType type. This array object is referenced by the reference variable ArrayName. Let's understand the creation of Java's two-dimensional array with an example: Here, the reference variable a points to a two-dimensional array object that represents a ... Note: When we create a 2D array object using the new keyword, the JVM (Java Virtual Machine) allocates the memory required for the two-dimensional array and initializes the memory spaces with the default values according to the data type of the array object.
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › Array2dBasics › a2dBasics.html
10.1. Introduction to 2D Arrays — AP CSA Java Review - Obsolete
Arrays in Java can store many items of the same type. You can even store items in two-dimensional (2D) arrays which are arrays that have both rows and columns. A row has horizontal elements. A column has vertical elements.
🌐
Medium
medium.com › @AlexanderObregon › understanding-multi-dimensional-arrays-in-java-7ead0c3937dd
Understanding Multi-Dimensional Arrays in Java
February 22, 2025 - While two-dimensional arrays are the most commonly used, Java allows arrays with any number of dimensions. For example, you can have a 3D array where each element in the array is a 2D array.