LumberSzquatch
LumberSzquatch

Reputation: 1083

How would you convert each int element of a 2D Array into a String?

I have a 10x10 int[][], each element is a random int. For my specific purpose, I need to convert each int value into a String so I can use those values as an argument in Label(text: String). I want to be able to traverse my array and do this conversion on each iteration. Obviously this is all I can muster up for this problem:

for (int row = 0; row < matrix.length; row++) {
            for (int column = 0; column < matrix[row].length; column++) {


            }
        }

I tried using the toString() on each index, but NetBeans wasn't liking it, because I was obviously using it incorrectly. So if someone could give me some guidance on how this process works it would be greatly appreciated. And it may go without saying, but I'm still learning.

Upvotes: 0

Views: 1099

Answers (1)

Chiseled
Chiseled

Reputation: 2300

Your loops seems to be alright. User Integer.toString() to convert an int to a String

for (int row = 0; row < matrix.length; row++) 
{
    for (int column = 0; column < matrix[row].length; column++) 
    {
       String matrixElementStr = Integer.toString(matrix[row][column]); 

       // Call some method "Label(text: String)" with  "matrixElementStr" as a parameter
    }
}

Upvotes: 1

Related Questions