Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda