I have read documents for
StandardSetController, but I don't understand what it is or why to use it.
ApexPages.StandardController (documentation) encapsulates just a single Sobject (e.g. Account, Opportunity).
ApexPages.StandardSetController (documentation) contains a list of records (one or more), and has additional functions to facilitate pagination (moving between pages) and updating a number of records at once.
For example in test class when we initialize
Account objAccount = [SELECT Name FROM Account LIMIT 1]; ApexPages.StandardController standctrl = new ApexPages.StandardController(objAccount );
List<account> accountList = [SELECT Name FROM Account LIMIT 20]; ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);
It is also important to note that
The maximum record limit for StandardSetController is 10,000 records. Instantiating StandardSetController using a query locator returning more than 10,000 records causes a LimitException to be thrown. However, instantiating StandardSetController with a list of more than 10,000 records doesn’t throw an exception, and instead truncates the records to the limit.
so use the query locator instantiation to ensure you don't have unexpected truncation occurring.