I need to break the string that is passed to my application from an external source. This string is limited to the caret "^" , and this is how I split String into an array
String[] barcodeFields = contents.split("\\^+");

This works fine, except that some of the fields passed in are empty, and I need to consider them. I need to insert either "" , or "null" or "empty" in any missing field.
And the missing fields have sequential delimiters. How to split a Java string into an array and insert a string such as "empty" as placeholders where there are consecutive delimiters?
source share