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 8452339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:28:28+00:00 2026-06-10T11:28:28+00:00

What is the best way to save an ArrayList of strings to SharedPreferences in

  • 0

What is the best way to save an ArrayList of strings to SharedPreferences in API level 8? The only way i can think of now is to save all of the strings into one string separated by commas and save it that way. But I don’t know if there is a maximum size for strings.

Is there a better way to do this?

  • 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-10T11:28:30+00:00Added an answer on June 10, 2026 at 11:28 am

    I suggest you to save the arraylist as Internal Storage File in Android. For example for a arraylist named text_lines:

    Internal storage File IO (Writing) :

    try {
       //Modes: MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITABLE
       FileOutputStream output = openFileOutput("lines.txt",MODE_WORLD_READABLE);
       DataOutputStream dout = new DataOutputStream(output);
       dout.writeInt(text_lines.size()); // Save line count
       for(String line : text_lines) // Save lines
          dout.writeUTF(line);
       dout.flush(); // Flush stream ...
       dout.close(); // ... and close.
    }
    catch (IOException exc) { exc.printStackTrace(); }
    

    Interal storage File IO (Reading) :

    FileInputStream input = openFileInput("lines.txt"); // Open input stream
    DataInputStream din = new DataInputStream(input);
    int sz = din.readInt(); // Read line count
    for (int i=0;i<sz;i++) { // Read lines
       String line = din.readUTF();
       text_lines.add(line);
    }
    din.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to save several strings on android? I thought that
What is the best way to save enums into a database? I know Java
What is the best way to save a URL or symbols into a MYSQL
I'm trying to figure out the best way to save a simple one-to-many relationship
what is the best way to save a list of strings to the settings
What is the best way to save a user profile with Google App Engine
What is the best way to save the state of a program. Maybe that
Is converting a file to a byte array the best way to save ANY
What is the best and simplets way to save two values from two different
I'm wondering what the best way is to use the XDocument.load and save methods

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.