I have an list of object eg:

List a = 1 , 2, 3, 4

now i want to push an object in position 2 , i.e

a.push(5,2) // push 5 in position 2
// 1,2,5,3,4 is the value of a

how can i achive this in apex?

  • 3
    I've downvoted this one because there is no apparent research done.
    – Derek F
    Jul 7 at 11:19
  • The List Class documentation is a good place to start. Jul 7 at 20:11
  • yes, i see my fault i don't see further downvotes as necessary -_-
    – Akash Jain
    Jul 8 at 9:45

1 Answer 1


This is the type of thing that you should look at the official documentation for as part of your research.

From the documentation on the List class, the .add(index, listElement) looks like it should be a natural fit.

And after a quick test, it does do exactly what you'd hope.

List<Integer> alist = new List<Integer>{1, 2, 3, 4};
aList.add(2, 5);

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