转换String类型中定义的用户对象

时间:2015-03-03 15:21:55

标签: java string

我有下面的pojo名为eurrexcashMessageObject,带有相应的setter和getters

public class eurrexcashMessageObject implements Cloneable{  

    private String  PaymentDate;
    private String CCPTradeId;
    private String Currency;
    private String Contract_Id;
    private String PaymentAmount;

    //include seeters & getters also
    }

现在有一种方法可以检索列表

List<eurrexcashMessageObject> listcashmessage1 = eurexcashParsing.getcashmessageojects();

因此您可以看到检索到的列表是eurrexcashMessageObject类型,现在我正在迭代列表,如下所示..

for(int i = 0; i < listcashmessage1.size(); i++)
            {

                String PaymentDate = String.valueOf(listcashmessage1.get(0));
                String CCPTradeId  = String.valueOf(listcashmessage1.get(1));                                         
                String Currency = String.valueOf(listcashmessage1.get(2));
                String Contract_Id =  String.valueOf(listcashmessage1.get(3));
                String PaymentAmount = String.valueOf(listcashmessage1.get(4));

现在我可以看到,在变量PaymentDate中,字符串不存储,CCPTradeId,Currency,Contract_Id,PaymentAmount的情况类似 你能告诉我如何将列表内容转换为for循环中的字符串

2 个答案:

答案 0 :(得分:2)

listcashmessage1.get(0)将返回列表中存储在索引0处的对象。调用listcashmessage1.get(i).yourGetter()以获取实际值。

答案 1 :(得分:1)

您可以使用for-each循环:

for (eurrexcashMessageObject emo : listcashmessage1) {
  String paymentDate = emo.getPaymentDate();
  //etc.
}