2016-10-17 95 views
-8

我有一个对象,它又包含其他对象。现在,我必须遍历这个主对象,然后选择每个对象,然后遍历它们以查明它们中是否存在任何空字段。如果对象本身是空的,我必须将它从主对象中剪除。对此有任何想法请。循环遍历java中的对象

public class Transactions { 

private Integer totalTransactionCount = null; 
private List<Transaction> transactionsList = new ArrayList<Transaction>(); 

} 

public class Transaction { 

private String amount = null; 
private Foreign foreign = null; 
} 

public class Foreign { 

private String amount = null; 
private String commissionAmount = null; 
private String exchangeRate = null; 
} 

现在我这里有一个交易对象,我要循环throught它的每一个领域,并通过各自的领域依次循环,找出任何空/空字段。

+5

这是非常基本的编程,你应该阅读一些教程。 – abbath

+3

请提供样本代码 – Nyakiba

+1

也这种需求听起来很混乱。你能更具体地了解你的任务吗? –

回答

2

通过列表的列表循环伪代码:

for each (innerList in outerList) do 
    if(innerlist.size == 0) then 
     //Code for removing empty inner lists. 
    else 
     for each (object in innerList) do 
      //Check if objects are empty as well and remove it 
     end for 
    end if 
end for 

编辑:他指出缺乏研究。
我想指出,你还没有真正做好你的研究,只需通过Google搜索iterate list of object以及iterate list of list of object我有很多解决方案。
更不用说这里已经问过堆栈溢出的问题,请阅读first answer of this post