有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在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;
}

现在我有了一个Transaction对象,我必须循环遍历它的每个字段,然后循环遍历它们的字段以找出任何空字段


共 (1) 个答案

  1. # 1 楼答案

    用于在列表中循环的伪代码:

    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
    

    编辑:指出缺乏研究
    我想指出的是,你没有真正正确地完成你的研究,仅仅通过谷歌搜索iterate list of objectiterate list of list of object我得到了很多解决方案
    更不用说关于堆栈溢出的问题了,请阅读first answer of this post