2

I have a List of string array already populated in storeInv. How do i change a specific element in the string array? For example the code below...

Thanks =]

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.
3
  • And store[1] = 123; doesn't give you an error? Commented Jun 8, 2010 at 0:29
  • 1
    @battousai622: you mean something like store[5] = store[1] ? Commented Jun 8, 2010 at 0:32
  • I'm pretty sure you mean storeInv.set(5, store); But you don't need to, because it's already there. Commented Jun 8, 2010 at 1:07

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

the set method isn't working for me. I can't get it to show up in the autocomplete in Eclipse, and I try using it on a String[]. Huh?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.