JAVA实现二维数组的行列转换
public class Test {
public static void main(String[] args) {
String[][] oldArray = { {"公开单位1","公开单位2","公开单位3","公开单位4","公开单位5","公开单位6"},
{"DL_GKBM1","DL_GKBM2","DL_GKBM3","DL_GKBM4","DL_GKBM5","DL_GKBM6"},
{"string1","string2","string3","string4","string5","string6"},
{"text1","text2","text3","text4","text5","text6"},
{"like1","like2","like3","like4","like5","like6"}};
String[][] newArray = new String[oldArray[0].length][oldArray.length];
for(int i=0 ; i<oldArray.length;i++){
for(int j=0; j<oldArray[i].length;j++){
newArray[j][i]=oldArray[i][j]; //转置核心
}
}
System.out.println("This is old Array");
for(int i = 0;i<newArray.length;i++){
for(int j = 0;j<newArray[i].length;j++){
System.out.print(newArray[i][j]+" ");
}
System.out.println("");
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。