How to add strings from one array into another array in Java

后端 未结 3 960
野性不改
野性不改 2020-12-22 12:28

I have an array of strings called initStrings and an array called squares. I need to take the strings from initStrings and add them one by one into different rows in the arr

相关标签:
3条回答
  • 2020-12-22 13:11

    You cannot put those strings into an integer array. squares should be an array of string. If it were, you could do :

    squares[col][rows] = initStrings[(col * squares.length + rows) % initStrings.length];
    
    0 讨论(0)
  • 2020-12-22 13:13

    it's a little bit confusing what you're trying to achieve, but the answer to your question is that you need another loop to run on the initStrings array (which you called as a function. also it's a 1 dimension array so you need to understand what you want to put inside the squares array which is 2 dimensions)

    hope this helps

    0 讨论(0)
  • 2020-12-22 13:28

    Something like: In the outer loop: String tempStr= InitStrings[rows]; In the inner loop: squares[cols][rows]= tempStr.chatAt(cols);

    But why you define 'squares' as int?

    0 讨论(0)
提交回复
热议问题