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

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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