将字符串拆分为字符串数组,然后将数组拆分为 java 或 groovy 中的哈希映射

Split the string to string array then split the array to hashmap in java or groovy

我有如下字符串

SUB_SYSTEM_ERROR@!@从子系统获取错误@$@Record already Exists@!@Record Already Exists

首先我必须用@$@分割字符串。 hten 数组就像

SUB_SYSTEM_ERROR@!@从子系统获取错误,记录已存在@!@记录已存在

然后我用@!@ 拆分数组并像下面那样制作哈希图。

(SUB_SYSTEM_ERROR,从子系统获取错误) (记录已存在,记录已存在)

请在 groovy 或 java 中提供帮助。

使用:

x.split('@\$@').collect { it.split('@!@') as List }​.collectEntries()​

其中 x 是您的输入字符串