【问题标题】:Looping through Object of Objects in java [closed]在java中循环对象的对象[关闭]
【发布时间】:2017-02-26 10:18:28
【问题描述】:

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

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 对象,我必须遍历它的每个字段,然后依次遍历它们的字段以找出任何 null/空字段。

【问题讨论】:

  • 这是非常基础的编程,你应该阅读一些教程。
  • 请提供示例代码
  • 这个要求听起来也很混乱。你能更具体地说明你的任务吗?
  • 请添加您的代码
  • 如果你解释什么对象,你描述它的方式,它可能意味着什么,它可能会有所帮助,对象是类层次结构的顶部,但是父对象是什么?一个列表?放?大批?什么是子对象?用户?书?课程项目?

标签: java loops iteration


【解决方案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 我得到了很多解决方案。
更不用说已经在 Stack Overflow 上提出的问题,请阅读first answer of this post

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-18
    • 2014-06-16
    • 1970-01-01
    相关资源
    最近更新 更多