2010-06-08 3 views
2

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

Спасибо =]

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. 
+0

И 'магазин [1] = 123;' не выдаст сообщение об ошибке? – Artefacto

+1

@ battousai622: вы имеете в виду что-то вроде * магазин [5] = магазин [1] *? – SyntaxT3rr0r

+0

Я уверен, что вы имеете в виду 'storeInv.set (5, store);' Но вам это не нужно, потому что оно уже есть. –

ответ

5
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); 
+0

ic, thanks =]]] – nubme

+0

Метод набора не работает для меня. Я не могу заставить его отображаться в автозаполнении в Eclipse, и я пытаюсь использовать его на String []. А? –

Смежные вопросы