So I have 5000+ ship coordinates, They're Longitude & Latitude coordinates. I'm wondering what would be the best way to store these for each ship. Each ship will have an unknown amount of coordinates.
Initially I was thinking a double 2D array similar too:
double [][] array = new double[][];
But I have no idea of the size I will need.
I don't know if a Hashmap
will work since there's no real "key", I was thinking an ArrayList
of List
's, but I was not sure on the implementation and if it's the most viable option.
Make a ShipCoordinates
class
public class ShipCoordinates {
public final double latitude;
public final double longitude;
public ShipCoordinates(double lat, double lon) {
latitude = lat;
longitude = lon;
}
}
And store these objects into a List
List<ShipCoordinates> shipCoordinates = new ArrayList<>();
// Example of valid ship coordinates off the coast of California :-)
shipCoordinates.add(new ShipCoordinates(36.385913, -127.441406));
Maybe hashmap is not sobad afterall. Consider this?
static class Coords {
...
}
Map<Coords, String> map = new HashMap<Coords, String>();
map.put(new Coords(1700, 1272), "Some_ship");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With