Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:14:17+00:00 2026-06-07T09:14:17+00:00

Im having a list of results, ArrayList<PlacedObject> result : for(PlacedObject po : result){ float[]

  • 0

Im having a list of results, ArrayList<PlacedObject> result:

for(PlacedObject po : result){

     float[] results = new float[3];

     Location.distanceBetween(lastlocation.getLatitude()
     ,lastlocation.getLongitude()
     ,Double.parseDouble(po.lat)
     ,Double.parseDouble(po.lng) ,
     results);

     po.distance = results[0];
}

After the po.distance is set, i would like to sort my list by the distance property. In c# i would use linq, but is there any similar solution in java?

Thanks


Current solution:

Collections.sort(result, new Comparator<PlacedObject>(){
public int  compare(PlacedObject s1, PlacedObject s2) {
    return (int) (s1.distance - s2.distance);
}
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:14:18+00:00Added an answer on June 7, 2026 at 9:14 am

    This is accomplished with the implementation of a Comparator<T> class:

    A comparison function, which imposes a total ordering on some collection of objects. Comparators can be passed to a sort method (such as Collections.sort or Arrays.sort) to allow precise control over the sort order.

    It could be applied to your list with Collections.sort(list, comparator). Basically you implement your own Comparator and pass it to the method.

    An implementation could for instance use an anonymous inner class:

    Collections.sort(list, new Comparator<PlacedObject>() {
    
        @Override
        public int compare(PlacedObject po1, PlacedObject po2) {
            return Double.valueOf(po1.distance).compareTo(po2.distance);
        }
    });
    

    If you are only intersted in the maximum, as your headline indicates, there is also Collections.max which is applied in the identical way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problem with using ArrayList . First I'm new to Java, I'm trying
I am having list of char array by that I want to store all
Having a list of data object and something visual to represent each, where would
Im having a list of student names in a table , in the same
Consider having a list - Ferrari, Mclaren, Red Bull on A2, A5, A8 cells,
I am having a list like <li style=display: list-item; id=listChoices> <label class=topspace>Enter the Choices</label>
I am actually having a list of text boxes. I am using below code
I m having a ordered list having the structure <ol> <li> </li> <li> </li>
I'm having a dropdown list in my web page. And it contains two lists.
Here i am having a unordered list displaying two columns code and name .I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.