Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
I now have a List of Unit which is a List object which contains lots of Units. Now I need to find the nearest Units from List object to Unit x. Cap the results by limit.
privateList<Unit> nearestUnits(List<Unit> lists,Unit x,int limit){List<Unit> output =newArrayList<>();// how do I sort lists object in such a way so that I can get nearest units here to "x"?return output;}
We have lat/long present in the Unit class so we can use that to calculate euclidean distance and do the comparison. I am confused on how to sort the list of units by shortest distance and get the nearest units. I am working with Java 7 as of now so I can't use Java 8.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that
you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice
sessions to improve your knowledge and scores.
manpreet
Best Answer
2 years ago
I have a
Unit
class which has lots of fields in it as shown below:I now have a List of
Unit
which is aList
object which contains lots of Units. Now I need to find the nearest Units fromList
object toUnit x
. Cap the results by limit.We have lat/long present in the
Unit
class so we can use that to calculate euclidean distance and do the comparison. I am confused on how to sort the list of units by shortest distance and get the nearest units. I am working with Java 7 as of now so I can't use Java 8.