有没有一种方法可以将三个单维数组转换为多维数组。 例如,我有三个数组(文本、转发、地理),如何合并它们,使其显示为:-
我想要合并的数组类似于 text = 'hello, 'hello'。 retweets = '2,5' 和 geo = '19912, 929293'。
并且应该导致:-
combined =
[hello, 2, 19912
hello, 5, 929293]
等等...所有数组的大小都相同。我知道我应该以某种方式遍历 while for 循环,但不太确定如何实现它。
感谢任何回复。
最佳答案
int count = ...;
String [] text = new String [count];
int [] retweets = new int [count];
int [] geo = new int [count];
// Fill arrays with data here
Object [] combined = new Object [count * 3];
for (int i = 0, j = 0; i < count; i++)
{
combined [j++] = text [i];
combined [j++] = retweets [i];
combined [j++] = geo [i];
}
关于java - 将数组转换为多维数组 - Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14709813/