【发布时间】:2018-11-20 10:55:29
【问题描述】:
我的代码有问题,我没有发现错误,一定是微不足道的。
// This list is filled with Objects of Matcher
ArrayList<Matcher > fullListForBundle = new ArrayList<>();
// making a new ArrayList
ArrayList<Matcher> bundlelist = new ArrayList<>();
// making a new object
Matcher currentBundle = new Matcher();
// Searching trough an Arraylist of Objects.
for (Matcher current : stockDataCompleteWithBundle)
{
// Get an Identifier
String han = current.getThirdColumn();
// Search through an other list to match identifier
for (int i = 0; i < fullListForBundle.size(); i++)
{
// If identifier matches then do:
if (fullListForBundle.get(i).getFifteenthColumn().equals(han))
{
// I want to get the right object and save it in currentBundle
currentBundle = fullListForBundle.get(i);
// !!! Here begins my problem !!!
// Then I want to change two Strings in that particular Object
currentBundle.setFirstColumn(current.getFirstColumn());
currentBundle.setThirteenthColumn(current.getSecondColumn());
// And add that object to a new Arraylist
bundlelist.add(currentBundle);
}
}
}
我的问题是:通过设置 firstColumn 和thirteenthColumn,fullListBundle.get(i) 对象中的数据发生了变化,而不是 currentBundle 对象。我错过了什么?
【问题讨论】:
标签: java variables arraylist local-variables