collection – Groovy – Inserting an item into a list according to an index

Question:

There is a method in Groovy to remove an element from a list by index – remove (n) Is there something like insert (n, m) in it? …

Answer:

Not all lists can be edited. But, for example, in an ArrayList , you can use the set() method to change the list item by index.

However, this method will only work for index values ​​that are not larger than the size of the list.

More details: https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#set(int,%20E)

Scroll to Top
AllEscort