Java get objects elements from List<Objects> and add to new ArrayList

42 views Asked by At

I am quite new to Java, but I seem to having a brain fog at the moment as I should be able to do this.

I have a List that includes quite a few items including Latitude and longitude elements, see model class shown. I want to retrieve just Lat and long doubles elements and add to a new Array List whilst iterating through.

I tried using the code below and get an empty ArrayList back. I know it is probably something very obviously simple I am getting incorrect, but I cannot see the wood for the trees at the moment!


ArrayList<LatLng> markerArrayList; *(Global variable) *

markerArrayList = new ArrayList<>();

for (OrmeauModel list : ormeauList) {

                    double markerLat = list.getMarker_lat();
                    double markerLong = list.getMarker_long();
                    LatLng latLong = new LatLng(markerLat, markerLong);
                    markerArrayList.add(latLong);
                }

**the Model class has getters from the following constructor**

public OrmeauModel(int marker_id, double marker_lat, double marker_long, String description, int image) {
        this.marker_id = marker_id;
        this.marker_lat = marker_lat;
        this.marker_long = marker_long;
        this.description = description;
        this.image = image;
    }
0

There are 0 answers