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

  • Home
  • SEARCH
  • 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 7172793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:41:23+00:00 2026-05-28T15:41:23+00:00

I need to save a string array to the database but it won’t let

  • 0

I need to save a string array to the database but it won’t let me. This is what I have:

 public long createEntry(String startTime, String endTime, String[] states) {
         ContentValues initialValues = new ContentValues();
         initialValues.put(START_KEY_TIME , startTime);
         initialValues.put(END_KEY_TIME , endTime);
         initialValues.put(KEY_STATE, states );

         return databaseConnect.insert(DATABASE_TABLE, null, initialValues);
}

But if I put string[] states in, it says that content values is not able to take an argument. How do I get around that? I was thinking I have 7 things in states, could I like have 7 separate strings and store stuff in each and then afterwards put all the strings back into an string array? Or would that be bad practice?

  • 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-05-28T15:41:25+00:00Added an answer on May 28, 2026 at 3:41 pm

    You cannot save String array into Database. But you can use this trick.

    1) So you have to convert it into simple String using convertArrayToString(String[] array) method. This will concatenate all elements of string using ‘comma’.

    2) When you would retrieve this String back from Database you could convert it back to String array using convertStringToArray(String str) method. This method will split the string from ‘comma’ and you will get your original array back.

    public static String strSeparator = "__,__";
    public static String convertArrayToString(String[] array){
        String str = "";
        for (int i = 0;i<array.length; i++) {
            str = str+array[i];
            // Do not append comma at the end of last element
            if(i<array.length-1){
                str = str+strSeparator;
            }
        }
        return str;
    }
    public static String[] convertStringToArray(String str){
        String[] arr = str.split(strSeparator);
        return arr;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

string[][] Tablero = new string[3][3]; I need to have a 3x3 array arrangement to
i have an array with 4 values: string[] selectedObject; how can i save all
I need to save images in certain folder of my application: string path=E:\AJAXEnabledWebSite1\images\gallery I
I need to cut out and save/use part of a string in C#. I
I need to save a user's login information in encrypted form for this application
I need to save a big file, sometime it takes a very long time
Need assistance to do this. Or advice about how to add string to string
I need to save on shared preferences some array of Strings and after that
I have the following data which I want to save in my DB (this
I have a multidim array from my $_POST but I have to serialize() then

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.