Skip to content Skip to sidebar Skip to footer

How To Store The Contents Of An Arraylist In One Column Of Table In Sqlite Database In Android?

I am having an arraylist of strings. I needt to store that arraylist in the 1 column of database. How can I do that?

Solution 1:

You can consider serializing an object into byte[] and saving it in your DB as a BLOB or going further encoding it in Base64 and saving as a TEXT. I'm not sure that any of these two are a good way to save your ArrayList - I'm just pointing options.

You might also consider creating other table and creating relation between them. There is a good pratice in databases called First Normal Form.

Solution 2:

take a String, append arraylist's index string with the help of loop

String all="";
for(int i=0;i<arraylist.lenght;i++)
{ 
    all=all+" "+ arraylist.get(i).tostring;
}

now store "all" in your DB field, only the problem with this is SIZE, hope you got what i meant

Post a Comment for "How To Store The Contents Of An Arraylist In One Column Of Table In Sqlite Database In Android?"