[英]Transform a List of List into into a List of another object
I use a method which returns a list of List
s. 我使用一种返回
List
的方法。 This List
contains 6 List
s, each List
contains 3 String : [[5, 0.01, 2], [7, 0.01, 3], [3, 0.02, 2], [8, 0.05, 3],[9, 0.1, 2], [6, 0.1, 3]]
此
List
包含6个List
,每个List
包含3个字符串: [[5, 0.01, 2], [7, 0.01, 3], [3, 0.02, 2], [8, 0.05, 3],[9, 0.1, 2], [6, 0.1, 3]]
Continuing from a previous answer... 从上一个答案继续...
But I have to split again this list in 3 differents values : [3, 0.01, 2]
但是我必须再次将此列表分为3个不同的值:
[3, 0.01, 2]
The main goal is to transform this list of object in list of Change. 主要目标是在“更改”列表中转换此对象列表。 A Change :
改变 :
public class Change {
private static final String value;
private static final String amount;
private static final String column;
...
}
I attempted but I think it's not the greatest way to accomplish : 我尝试过,但是我认为这不是最大的实现方式:
List saisie = ServiceTableau.getInstance().deserialiser(quantites);
List<String> saisieToStrings = new ArrayList<String>();
for (Object object : saisieIHM) {
saisieIHMToStrings.add(object != null ? object.toString() : null);
}
Is there a system method to do this? 有系统的方法可以做到这一点吗? I can't use external libraries
我不能使用外部库
Create a constructor in your Change
class: 在您的
Change
类中创建一个构造函数:
public Change( String input) {
String[] values = input.split(",");
this.value = values[0];
this.amount = values[1];
this.column = values[2];
}
And then pass that string when you create the list: 然后在创建列表时传递该字符串:
List<Change> saisieToStrings = new ArrayList<Change>();
for (Object object : saisieIHM) {
saisieIHMToStrings.add( new Change( object.toString()));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.