Java 映射要映射的字符串数组
我有一个字符串数组。如何将其转换为地图(字符串、对象)。我需要将其转换为数据对象 使用Java 映射要映射的字符串数组,java,string,object,map,mapping,Java,String,Object,Map,Mapping,我有一个字符串数组。如何将其转换为地图(字符串、对象)。我需要将其转换为数据对象 使用Map相当于。如果我们将您的案例应用于此,您将得到每个字符串指向另一个对象 如果这是您想要的,这将起作用: String[] strs = new String[]; //Your string array, initialized elsewhere Object[] os = new Object[]; //The objects that you want mapped. Map<String,
Map
相当于。如果我们将您的案例应用于此,您将得到每个字符串
指向另一个对象
如果这是您想要的,这将起作用:
String[] strs = new String[]; //Your string array, initialized elsewhere
Object[] os = new Object[]; //The objects that you want mapped.
Map<String, Object> m = new HashMap<String, Object>(); // I use HashMap because it is the most generic
for(int i = 0; i < strs.length; i++) {
m.put(strs[i], os[i]); //Add each object, os[i], to the map at position str[i]
}
您希望将每个字符串值映射到什么?能否详细说明您正在尝试进行的映射类型?或许可以给出一些示例。
List<String> a = Arrays.asList(strs);