0
list<integer> mynums = new list<integer>();
mynums.add(10);
mynums.add(20);
mynums.add(30);
mynums.add(20);
mynums.add(10);
mynums.add(5,60);
system.debug('list values'+mynums);

This is my code,when i want to insert an other number with index 5 it is throwing an error as shown above. Help me out.............

1 Answer 1

1

First make List<Integer> instead of list it is error.

second since index 5 value is not initiated yet you cannot push value directly at 5 index try to push it at 4 and it will work.

hope this helps.

2
  • 1
    Perfect Answer :) It works. Jun 20, 2018 at 12:06
  • Yea,i Know that works,but why can't i do in this way?
    – swetha a
    Jun 21, 2018 at 7:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .