2012-04-02 79 views
-2

我有一个包含对象值数组的列表。我必须从对象列表中显示值。如何从java中的列表中获取值

List InvoiceList =[{companyname=greytip1, invoiceno=GO/12/04/001, 
    billperiod=Apr 2012, invoicedate=2012-04-18 00:00:00.0, 
    servicecharge=2000.00, tax=399.00, netamount=2394.00, duedate=null, 
    mailed=false, isinelekka=false, amountpaid=null, filename=Invoice For 
    Apr 2012-1333340688550.pdf, cid=15, ismanual=true}, 
    companyname=greytip3, invoiceno=GO/12/04/002, billperiod=Apr 2012, 
    invoicedate=2012-04-05 00:00:00.0, servicecharge=5000.00, tax=500.00, 
    netamount=5498.00, duedate=null, mailed=false, isinelekka=false, 
    amountpaid=null, filename=Invoice For Apr 2012-1333340842337.pdf, 
    cid=16, ismanual=true}] 

从这个InvoiceList,我需要从每个对象获得netamount并添加它。

如何在java中做到这一点?

+0

请清理你的例子,并删除多余的位。这样,我们可以轻松识别您的问题,并帮助您更快。 – 2012-04-02 05:33:58

+0

这个例子不是有效的Java代码,再加上一个额外的'} - 它是你必须阅读的文本文件的一些内容吗? – 2012-04-02 05:39:59

回答

4

invoiceList[INDEX].PROPERTYNAME。例如:invoiceList[0].ismanual将返回true。基本上你需要在列表中遍历一个for循环,并且有一个全局变量,你可以在其中存储总和。

Decimal total = 0; 
for(Integer i = 0; i < invoiceList.length(); i++) 
{ total += invoiceList[i].netamount; 
}