Android App Development
iOS App Development
Flutter App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Founder. Opencart
Top Partners
In this article, we are going to learn how to store list in shared preference in Android. So let’s get started.
For storing list of object(String used in this article or any other object) into Shared preference, first we need to convert List<String> into string. And we easily convert list of object in Java or Kotlin into JSON string using Gson.
Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object.
Before using Gson in our project, please add below dependency to your app level Gradle file.
Gradle:
Converting List of object into JSON string:
Create your preference editor:
Shared preference to get data:
Accessing stored JSON string from shared preference as List of Object:
Here, type is used to tell Gson that we want this JSON to be translated to a List of Strings.
Happy Coding 🙂
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
Webkul is a truly trusted and supported IT Company to develop business ideas for e-commerce. They provide professional support after deploying the solution to production and be responsible to act for fixing the reported issues or system errors. We highly encourage to deal with Webkul for business development.
Hussein Zawia
Co-founder, 24Dokan
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.