public static Map < String , String > strToMap ( String text , String listDelimiter , String keyValueDelimiter ) { if ( StringUtils . isEmpty ( text ) ) { return EMPTY_MAP ; } String [ ] keyValuePairs = text . split ( listDelimiter ) ; Map < String , String > ret = new HashMap <> ( keyValuePairs . length ) ; for ( String keyValuePair : keyValuePairs ) { String [ ] keyValue = keyValuePair . split ( keyValueDelimiter , 2 ) ; if ( keyValue . length < 2 ) { ret . put ( keyValuePair , null ) ; } else { ret . put ( keyValue [ 0 ] , keyValue [ 1 ] ) ; } } return ret ; }
Creates a map by parsing text . Split text into key - value pairs using two delimiters . The first delimiter separates pairs and the second delimiter separates key and value .