Java ArrayList replace at specific index

Java ArrayList replace at specific index

Check out the set(int index, E element) method in the List interface

You can replace the items at specific position using set method of ArrayList as below:

list.set( your_index, your_item );

But the element should be present at the index you are passing inside set() method else it will throw exception.

Also you can check oracle doc here

Java ArrayList replace at specific index

Use the set() method: see doc

arraylist.set(index,newvalue);

Leave a Reply

Your email address will not be published.