Here's my list:
myList =
["HEADING","POST","POST","POST","CALL_TO_ACTION","HEADING","POST","POST","POST","CALL_TO_ACTION","HEADING","POST","POST","CALL_TO_ACTION"]
I would like to have some logic in place that would help me divide myList
into below three sub-lists (stored as, say, List<List<String> subLists
):
["HEADING","POST","POST","POST","CALL_TO_ACTION"]
["HEADING","POST","POST","POST","CALL_TO_ACTION"]
["HEADING","POST","POST","CALL_TO_ACTION"]
Please note, the number three comes from the number of occurrences of the element "HEADING"
(which I could find out using Collections.frequency(myList, "HEADING")
).