I have a 2d-array of variable number of rows and columns. The array is stored as JSON in the database. I have a requiremnt to add given elements after certain element specified by the user or remove a element specified by the user. Each elemet in the array is unique. The sample json value looks like [[4,5],[3,1,6,7],[34,21,55]]. Consider a situation I want to add 2 elements 12,13 after the element 7, the resultant array looks like [[4,5],[3,1,6,7,12,13],[34,21,55]]. And to remove if I given 1 as input the result should be [[4,5],[3,6,7,12,13],[34,21,55]].Using Gson I have parsed the json value stored to an array. How can I achieve it in Java with less time complexity.
My code to parse json data from db looks like
Gson gson = new GsonBuilder().create();
if (myTemplate.getQuestionOrder() != null) {
long[][] questionOrder = gson.fromJson(myTemplate.getQuestionOrder(), long[][].class);
}