Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to figure out how to replace a specific index in a arraylist of arraylists

The only stuff I've been able to find so far is how to just get the index with .get(x).get(y) I'm having no real luck with google at the moment, so I figured I'd finally make a post about it. Any help would be great, thanks in advance.

share|improve this question
 
Use set(int index, E o). See ArrayList#set –  peeskillet 13 mins ago
add comment

3 Answers

You can do

.get(x).set(y, value);
share|improve this answer
 
I tried doing that and I was getting an array index out of bounds. I tried .get(0).set(3, Title); Timer being a String variable. the array is 2 x 27, so I'm not getting why it's saying out of bounds. I'll mess with it some more and get back to you. Maybe I made a mistake –  user2965892 7 mins ago
 
works great, that was just a mistake, 3> 2 duh. my brain is practically shut off at the moment. Thanks a lot :) –  user2965892 2 mins ago
add comment

Something like this:

ArrayList<ArrayList<String>> s = . . .;
s.get(3).set(4, "new value");
share|improve this answer
add comment

As @peeskillet suggest a best solution..

But check this core java code if it have some sense.

String arrayList[] = {....your array content...};

for (String token : arrayList) {
         token = token.replace("x", "replaceanythings");
         token = token.replace("y", "replaceanythings");
        } 
share
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.