Java | Unable to add data to list created with Collections.emptyList()

|
| By Webner

If you initialize a List in Java with method Collections.emptyList(), you will not be able to add data to this list. You will not get any exception if you try to add data to it, but data will not be added.

The reason here is that Collections.emptyList() returns an immutable list instance.

To add data to your lists you have to initialize the lists with new keyword.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Web development or any other software development assistance please contact us at webdevelopment@webners.com

Leave a Reply

Your email address will not be published. Required fields are marked *