2011-11-03 76 views
0

我正在提取數據數組並在Java中的對象內設置這些數據。從數組中提取數據並將其設置在java中的對象中

我不知道,從數組中獲取數據後,如何將其設置爲一個對象?

請看看下面的代碼:

public class Legform implements Serializable { 

    private SecurityType securityType; 

    public SecurityType getSecurityType() { 
     return securityType; 
    } 

    // As well as a setter Method also present 
} 

我提取這腿型對象(上面一個)在這裏從另一個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; 

} 

可能有人幫助我嗎?

回答

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

非常感謝。 – Pawan

相關問題