Java: изменить элемент в предварительно заполненном списке массива строк - PullRequest
2 голосов
/ 08 июня 2010

У меня есть список массивов строк, уже заполненных в storeInv. Как мне изменить определенный элемент в массиве строк? Например код ниже ...

Спасибо =]

List <String[]> storeInv ;  //assume already populated with elements
String[] store = storeInv.get(5);
store[1] = 123;

store.set(5, store[1]);  //this gives me an error.

1 Ответ

5 голосов
/ 08 июня 2010
List <String[]> storeInv = ...
String[] store = storeInv.get(5);

// This updates an element in one of the arrays.  (You cannot
// assign an integer literal to a String or a String array element.)
store[1] = "123";

// Compilation error!  'store' is an array, so there is no 'set' method.
store.set(5, store);

// This updates an array in the list ... but in this
// case it is redundant because the 5th list element
// is already the same object as 'store'.
storeInv.set(5, store);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...