Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Java - Collection to keep the best results

I have a list of 2D points (a custom Node class). I would like to pick a Node and say "Ehy, the 10 closest node in my list are those ten"

Now, what's the problem: I would like to make something like:

ArrayList<Node> nodes; //list of nodes
            ArrayList<Node> topten; //list of nearest nodes
            Node currentNode; //the current point
            for (Node x : nodes){
                if (x.distance(currentNode) < (topten.THE_FURTHER_POINT()).distance(currentNode))
                    topten.ADD(x);

            }

I would like to know if there is already a Collection which have those pseudo-methods (THE_FURTHER_POINT and ADD) Those two methods should work like this:

THE_FURTHER_POINT: return the further point. The collection should be fixed-length, so this method should always return the last element (if I have 8 elements inside the topten, i should receive the node with index 7, if I have 10 elements I should receive the node with index 9)

ADD: everytime an elements is added, if the collection is full the latest elements get eliminated. The collection should be always ordinate, and this operation should be as quick as possibile (if I have 8 elements in the topten, I will end up with 9 elements after the add. if I have 10 elements, I will end up with 10 elements after the add)

Thank you a lot!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In the end, what i really was searching for was a collection

  • ALWAYS SORTED
  • WITH FIXED LENGTH

So... After reading Java PriorityQueue with fixed size I think I found my reply. This can be considered a duplicate question.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!