简体   繁体   English

您如何将2D数组的每个int元素转换为String?

[英]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 . 我有一个10x10 int[][] ,每个元素都是一个随机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) . 对于我的特定目的,我需要将每个int值转换为String以便可以将这些值用作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. 我尝试在每个索引上使用toString() ,但NetBeans不喜欢它,因为我显然使用不正确。 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. 它可能不言而喻,但我仍在学习。

Your loops seems to be alright. 您的循环似乎还不错。 User Integer.toString() to convert an int to a String 用户Integer.toString()将int转换为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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM