function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saumya SumanSaumya Suman 

Method does not exist or incorrect signature: void addall(String) from the type Set<String>

I am new to apex. I got above error when executing below codes of collection .Please help.

List<string> colors= new List<string>();
colors.add('Red');
colors.add('Blue');
colors.add('Blue');
system.debug('the size of the list is' + colors.size());
system.debug('the list contents are' + colors);
colors.remove(0);
system.debug('the list contents are' + colors);

Set<string> months = new Set<string>();
months.add('Jan');
months.add('Feb');
months.add('March');
system.debug('the elements in the set are' + months);
for(string st : months)
    system.debug('the elements in the set are' +st);
    months.add('Jan');
system.debug('the values in the set are' + months);
months.addall('colors');
system.debug('the added list values are' + months); 
colors.addall('months');
system.debug('the values in the List are' + colors);
system.debug('the size of the set is' + months.size());
Raj VakatiRaj Vakati
Try this code 


you no need to pass the addAll in string insted it will be refrerenced 
 
months.addall(colors);
system.debug('the added list values are' + months); 
colors.addall(months);

Complete code

 
List<string> colors= new List<string>();
colors.add('Red');
colors.add('Blue');
colors.add('Blue');
system.debug('the size of the list is' + colors.size());
system.debug('the list contents are' + colors);
colors.remove(0);
system.debug('the list contents are' + colors);

Set<string> months = new Set<string>();
months.add('Jan');
months.add('Feb');
months.add('March');
system.debug('the elements in the set are' + months);
for(string st : months)
    system.debug('the elements in the set are' +st);
    months.add('Jan');
system.debug('the values in the set are' + months);
months.addall(colors);
system.debug('the added list values are' + months); 
colors.addall(months);
system.debug('the values in the List are' + colors);
system.debug('the size of the set is' + months.size());