I have a string whose value can be Insert, Insert&Update or Update. Now based on this value, i have to create a Map as below.
Case 1 : When myString="Insert", i need output like this
"Database": [
{
"Action": "Insert"
}
]
Case 2 : When myString="Insert&Update", i need output like this
"Database": [
{
"Action": "Insert"
},
{
"Action": "Update"
}
]
Case 1 : When myString="Update", i need output like this
"Database": [
{
"Action": "Update"
}
]
I'm new to java and based on my knowledge what i'm doing currently is manually checking the condition and creating the list manually(something like below). Is there any way that I can split myString and automatically create this list?
Map<String, String> database = new HashMap<String, String>();
List<Map<String, String>> subList = new ArrayList<>();
if(myString.equals("Insert")){
database.put("Action", "Insert");
subList.add(database);
} else if(myString.equals("Insert&Update")){
database.put("Action", "Insert");
subList.add(database);
database = new HashMap<String, String>();
database.put("Action", "Update");
subList.add(database);
} else {
....
}