Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:24:50+00:00 2026-06-17T08:24:50+00:00

I wanted to save an ArrayList to SharedPreferences so I need to turn it

  • 0

I wanted to save an ArrayList to SharedPreferences so I need to turn it into a string and back, this is what I am doing:

// Save to shared preferences
SharedPreferences sharedPref = this.getPreferences(Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = this.getPreferences(Activity.MODE_PRIVATE).edit();
editor.putString("myAppsArr", myAppsArr.toString());
editor.commit();

I can retrieve it with String arrayString = sharedPref.getString("yourKey", null); but I don’t know how to convert arrayString back into an ArrayList. How can it be done?


My array looks something like:

[item1,item2,item3]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:24:51+00:00Added an answer on June 17, 2026 at 8:24 am

    You have 2 choices :

    1. Manually parse the string and recreate the arraylist. This would be pretty tedious.
    2. Use a JSON library like Google’s Gson library to store and retrieve objects as JSON strings. This is a lightweight library, well regarded and popular. It would be an ideal solution in your case with minimal work required. e.g.,

      // How to store JSON string
      Gson gson = new Gson();
      // This can be any object. Does not have to be an arraylist.
      String json = gson.toJson(myAppsArr);
      
      // How to retrieve your Java object back from the string
      Gson gson = new Gson();
      DataObject obj = gson.fromJson(arrayString, ArrayList.class);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to save a string to a file and read it back, so
I wanted to know about Data Type implementation in PHP so I need a
I wanted to know that if I am doing correctly, regarding retain and release
If I wanted to save a contact form submission to the database, how can
Assuming I was making a Temporal-esque time travel game, and wanted a to save
I wanted to write a simple processing function. It should run like this: Load
I wanted to know if this was thread safe/ good practice. My IOC is
I wanted to make a little script to save me some typing, but unfortunately
... and save it into self-defined object type? I'm using PostgreSQL. When I have
I'm new to android,I have an edit text and I wanted to save the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.