Saving ArrayLists in SQLite databases

前端 未结 6 2262
傲寒
傲寒 2020-11-30 03:42

So I want to save an ordered set of double values, and I want to be able to insert, retrieve or delete any value from this easily. As of such, I\'m using a an ArrayList, whe

6条回答
  •  不知归路
    2020-11-30 04:00

    To Insert :

    ArrayList inputArray=new ArrayList();
    

    Add Values to inputArray

    Gson gson = new Gson();
    
    String inputString= gson.toJson(inputArray);
    
    System.out.println("inputString= " + inputString);
    

    Use "inputString" to save the value of ArrayList in SQLite Database

    To retreive:

    Get the String from the SQLiteDatabse what you saved and changed into ArrayList type like below:

    outputarray is a String which is get from SQLiteDatabase for this example.

    Type type = new TypeToken>() {}.getType();
    
    ArrayList  finalOutputString = gson.fromJson(outputarray, type);
    

提交回复
热议问题