gpt4 book ai didi

java - 从数组中提取并将其设置在java中的对象中

转载 作者:行者123 更新时间:2023-12-02 08:07:07 25 4
gpt4 key购买 nike

我正在提取数据数组并将这些数据设置在 Java 中的对象内。

我不知道,从数组中获取数据后,如何将其设置为对象?

请看下面的代码:

public class Legform implements Serializable {

private SecurityType securityType;

public SecurityType getSecurityType() {
return securityType;
}

// As well as a setter Method also present
}

我在这里提取这个 LegForm 对象(上面的对象),如另一个 java 类所示:

Legform[] legdata = orderform.getLeg();

循环访问这些数据后,我需要将它们设置在另一个名为 Leg(Java 类)的对象中

for(int i = 0; i < legdata.length; i++) {
System.out.println(legdata[i].getSecurityType());
// Here do i need to set the data into the Leg Object
}

我需要将提取的信息设置为腿部对象腿部对象如下所示:

public class Leg
{
public String securityType;

}

有人可以帮我吗?

最佳答案

List<Leg> legs = new ArrayList<Leg>(legdata.length);
for (Legform ld: legdata){
Leg leg = new Leg();
leg.securityType = ld.getSecurityType();
legs.add(leg);
}

关于java - 从数组中提取并将其设置在java中的对象中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7993766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com