将字符串数组转换为散列表 [英] Converting string array to hashmap

查看:188
本文介绍了将字符串数组转换为散列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下回应

I have the following response

T2269|175@@2a1d2d89aa96ddd6|45464047

通过使用 split(\\ |),我已将其转换为字符串数组对象。每个字段的含义如下:

By using the split("\\|") i have converted into string array object. The meaning for the each field is as follows:

T2269                  id
175@@2a1d2d89aa96ddd6  cid
45464047               refno

不,我必须将它转换成HashMap对象。他们的任何解决方案为上述..

No i have to convert it into HashMap object . Is their any solution for the above..

上面的回应是举例。实际上,字符串数组对象的长度是36。

The above response is given for example. In real, the length of the string array object is 36.

推荐答案

final String[] fields = input.split("\\|");
final Map<String, String> m = new HashMap<String, String>();
int i = 0;
for (String key : new String[] {"id", "cid", "refno"})
  m.put(key, fields[i++]);

这篇关于将字符串数组转换为散列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆