1

I have an ArrayList, initialized as follows:

    public static List<int[]> items = new ArrayList<int[]>();

I add items to it like this:

    items.add(new int[] {2,0,1,0,1});

Can I change a specific entry on an array already on the ArrayList (for example: the 2 at index 0), or do I have to recreate the array every time with items.set()?

1 Answer 1

3

You can do this:

int[] array = items.get(0);
array[0] = <new value>;
Sign up to request clarification or add additional context in comments.

2 Comments

I know. Writing it in two lines to make it explicit for OP how this works.
This is what I was looking for! Thank you.

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.