Set<String> Accountids = new Set<String>(); for (Account a: [Select Id from Account limit 5]) Accountids.add(a.Id); system.debug('The size of the set is'+accountids.size()); for (Account a: [Select Id from Account limit 5]) Accountids.add(a.Id); system.debug('The size of the set is'+accountids.size());