Java 将值从列表添加到另一个列表

Java 将值从列表添加到另一个列表,java,android,arraylist,hashmap,Java,Android,Arraylist,Hashmap,我试图将ListArraycoords中的值添加到ListArraylinhasCoords中,但是linhasCoords无法获取所有值 我的观点是,对于每个ID,保存所有坐标Lat和Long 我的代码: 您可以看到,linhasCoords没有在coords之前生成所有的值及其,我不知道为什么 if (idAtual == idAnterior) { coords.add(new LatLong(x,y));

我试图将ListArray
coords
中的值添加到ListArray
linhasCoords
中,但是
linhasCoords
无法获取所有值

我的观点是,对于每个ID,保存所有坐标Lat和Long

我的代码:

您可以看到,
linhasCoords
没有在
coords
之前生成所有的值及其
,我不知道为什么

 if (idAtual == idAnterior) {



                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " Coords: " + coords);



            } else {



                    linhasCoords.put(idAnterior,coords);



                    idAnterior = idAtual;



                    coords.clear();

                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " LinhasCoords: " + linhasCoords);

            }      
因此,如果IDatal等于IDInterior,则不会将其添加到linhasCoords,而只添加到coords。 将其替换为以下内容:

 if (idAtual == idAnterior) {

                    linhasCoords.put(idAnterior,coords);

                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " Coords: " + coords);



            } else {



                    linhasCoords.put(idAnterior,coords);



                    idAnterior = idAtual;



                    coords.clear();

                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " LinhasCoords: " + linhasCoords);

            }      

请在这里提供没有外部链接的代码。我认为这不是问题所在。可能您不明白,但当IDatal等于IDinterior时,坐标区域会附加到坐标系中,当我获得不同的id时,我会将前面所有坐标系中的坐标添加到linnhasCoords中。
 if (idAtual == idAnterior) {



                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " Coords: " + coords);



            } else {



                    linhasCoords.put(idAnterior,coords);



                    idAnterior = idAtual;



                    coords.clear();

                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " LinhasCoords: " + linhasCoords);

            }      
 if (idAtual == idAnterior) {

                    linhasCoords.put(idAnterior,coords);

                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " Coords: " + coords);



            } else {



                    linhasCoords.put(idAnterior,coords);



                    idAnterior = idAtual;



                    coords.clear();

                    coords.add(new LatLong(x,y));

                    Log.d("TRECHOS", " LinhasCoords: " + linhasCoords);

            }