0

我需要将过时的对象替换ArrayList<Station>TreeMap<Integer, ArrayList<Station>>.

TreeMap> 在 ArrayList 中只有一部分 Station 对象。

任何人都知道以快速流畅的方式做到这一点的方法吗?我的应用程序对时间敏感,它处理得越快越好,因为它正在处理大量数据。

如果有帮助,我可以在这里发布我的代码

编辑:

这是代码:

public ArrayList<Station> smoothPingPong(ArrayList<Station> dados){
    ArrayList<Station> pingPongs = new ArrayList<>();
    TreeMap<Integer, ArrayList<Station>> tmap = new TreeMap<>();
    int tmap_key = 0;

    for(int i = 0; i<dados.size(); i++) {
        if(dados.get(i).getPingPong() == 1)     {
            pingPongs.add(dados.get(i));
        }
    }

    ArrayList<Station> next = new ArrayList<Station>();
    for(Station d : pingPongs)  {
        if(!next.isEmpty() && next.get(next.size() - 1).getId() != d.getId() - 1)       {
            tmap.put(tmap_key++, next);
            next = new ArrayList<Station>();
        }
        next.add(d);
    }

    if(!next.isEmpty())     {
        tmap.put(tmap_key++, next);
    }

    for(Integer a : tmap.keySet()){ 
        //Processes the treemap updating it
    }
}

现在我需要回到 ArrayList dados 中的 Stations 并用我在 TreeMap 上的 Stations 更新它。

4

1 回答 1

1

因为您没有创建新的站对象,所以您不需要更新任何内容,站对象在您的所有集合中共享相同的引用。

在这种情况下,您只是返回 Station Collection 的一个子集,但对象本身是相同的。

于 2013-07-10T01:21:42.777 回答