可能重複:
java: How to split a 2d array into two 2d arrays如何將2D數組拆分爲左右數組?
所需要的是拆分此陣:
int[][] bitblock = {
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0},
{1,0,1,0,1,0,1,0}};
這是一個8 * 8的陣列,我想把它分成左右陣列並將它們存儲在這裏:
int[][] leftblock = new int [bitblock.length][bitblock[0].length/2];
int[][] rightblock = new int [bitblock.length][bitblock[0].length/2];
我使用的方法Syste.arraycopy,我能夠給bitblock分裂,上下排列,我有點掙扎分裂它左,右:
System.arraycopy(bitblock, 0, leftblock, 0, leftblock.length);
System.arraycopy(bitblock, rightblock.length, rightblock, 0, rightblock.length)
是否有人可以幫忙嗎?謝謝
希望這個幫助:http://stackoverflow.com/questions/5463781/java-how-to-split-a-2d-array-into-two-2d-arrays –
你不能這樣做只有兩個'陣列拷貝,你的數據不是連續的。 – Vlad