我有一个字符串列表。
String result[] = { "1=AccountId93",
"10188=930.0", "10190=Mkt930", "1=AccountId94",
"10188=940.0", "10190=Mkt940", "1=AccountId95",
"10188=950.0", "10190=Mkt950" };
我想将列表放入对象数组中,其中对象是例如 AccountId93,930.0,Mkt930
我怎样才能重新排序这个数组???注意,有名称值对可以使用,但映射将不起作用,因为键值将相互覆盖
最佳答案
List<Item> items = new ArrayList<Item>();
for (int i = 0; i < result.length; i+=3) {
String value1 = result[i ].split("=")[1];
String value2 = result[i+1].split("=")[1];
String value3 = result[i+2].split("=")[1];
items.add(new Item(value1, value2, value3));
}
这样就可以了。 Item
是表示存储在字符串数组中的数据集的类。
关于java - 将字符串数组转换为对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5802982/