You need to sign in to do that
Don't have an account?
Map Constructor
public class TEST { Map<Integer, String> m1 = new Map<Integer, String>(); m1.put(1, 'First item'); m1.put(2, 'Second item'); }Why do I get this error: Expecting Right Parenthesis found '1' ??
This is because you didn't include it in method. Refer following code.
Mark this as solve and choose best answer if your issue resolved.
Regards,
Santosh chitalkar
All Answers
This is because you didn't include it in method. Refer following code.
Mark this as solve and choose best answer if your issue resolved.
Regards,
Santosh chitalkar
public class TEST {
//constructor
public TEST(){
Map<Integer, String> m1 = new Map<Integer, String>();
m1.put(1, 'First item');
m1.put(2, 'Second item');
}
}
Adelchi
public with sharing class TEST {
Map<Integer, String> m1 = new Map<Integer, String>{1=>'First item',2=>'Second item'};
}
OR
public with sharing class TEST {
Map<Integer, String> m1 = new Map<Integer, String>();
//Constructor
public TEST(){
m1.put(1, 'First item');
m1.put(2, 'Second item');
}
}
Please mark this as resolved if this suffice.
Thanks
In this case, refer following code,
Mark this issue as solved and choose best answer.
Regards,
Santosh Chitalkar