2012-04-02 75 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; 
}