I need to split an input and put it in to a list according to a list of keywords or delimiters that I have created.
I've tried simply splitting the string by spaces and then processing it afterwards, but the problem is that some of my keywords have spaces in them so they are split apart which causes undesired behavior.
// "Jr.", "III", "Sr", "pro se" are all keywords in my list
String input = "Abraham Lincoln Jr. III Sr pro se";
String [] splitBySpace = input.split(" ");
List<String> separatedName = new ArrayList<>(Arrays.asList(splitBySpace);
My list ends up being: {Abraham, Lincoln, Jr., III, Sr, pro, se}
And I would like it to be: {Abraham, Lincoln, Jr., III, Sr, pro se}
This output would also work: {Abraham Lincoln, Jr., III, Sr, pro se}
(I don't need the strings that are not in my delimiter list to be split apart)