Учитывая 2d массив.Если [i][0] == name
, как мне переместить его в последний элемент массива?
String[][] array2d = [ [continents, name, Asia, Europe, Africa, Australia, South America, North America, Antartica],
[profession, Teacher, Doctor, Lawyer],
[brand, Apple, Samsung],
[name, Lisa, Peter, Sam, Jake],
[profession, Engineer, Professor, Dentist, Driver],
[sex, value, Male, Female],
[exp, value, 1, 2, 3, 4, 6]]
Мой желаемый вывод -
[ [continents, name, Asia, Europe, Africa, Australia, South America, North America, Antartica],
[profession, Teacher, Doctor, Lawyer],
[brand, Apple, Samsung],
[profession, Engineer, Professor, Dentist, Driver],
[sex, value, Male, Female],
[exp, value, 1, 2, 3, 4, 6],
[name, Lisa, Peter, Sam, Jake]
]
Ниже приведены коды
String[][] newArray =new String[array2d.length][];
for (int i = 0; i < newArray.length; ++i) {
newArray[i] = new String[array2d[i].length];
for (int j = 0; j < newArray[i].length; ++j) {
if (array2d[i][0] != "name") {
newArray[i][j] = array2d[i][j];
}
}
}
Однако на выходе получается
[[continents, name, Asia, Europe, Africa, Australia, South America, North America, Antartica],
[profession, Teacher, Doctor, Lawyer],
[brand, Apple, Samsung],
[null, null, null, null, null],
[profession, Engineer, Professor, Dentist, Driver],
[sex, value, Male, Female],
[exp, value, 1, 2, 3, 4, 6]]
Спасибо!