简体   繁体   中英

Accessing elements of object that extends ArrayList

I'm pretty new to Java, and I'm trying to program an app that displays a list of points on a map. I've got that much working, now I want to work out the boundaries of the places to set the zoom area. To do this I have created a class that contains all my place objects, extending ArrayList() as below:

public class PlaceList extends ArrayList<Place> {
private static final long serialVersionUID = 4374092139857L;

public PlaceList() {
}

public Double getNorthernLimit() {
   double mostNorthern;
       for (Place curPlace: ???????) {
        //check each place and keep most northern one
       }

   return mostNorthern;
}

My problem is that I don't know how to access the Arraylist of objects (where the ??? is). I want to loop through them out to determine the most northerly point.

Any help would be appreciated.

Just use this :

for (Place curPlace : this)
{
}

I would personally avoid extending ArrayList<Place> to start with though - I prefer to use composition over inheritance, so I would normally make my class contain a List<Place> instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM