How to sort an array of objects(Points) in Java?

前端 未结 2 496
遥遥无期
遥遥无期 2021-01-21 01:03

So I wanna sort an array of Points using the built in sorting method, by a specific coordinate, say x. How can I do this? Heres a sample code:

Point A[] = new Po         


        
2条回答
  •  旧时难觅i
    2021-01-21 01:38

    You can also use Apache Commons Bean Comparator

    http://commons.apache.org/beanutils/apidocs/org/apache/commons/beanutils/BeanComparator.html

    And then do something like

    import org.apache.commons.beanutils.BeanComparator;
    
    Arrays.sort(A, new BeanComparator("x"));
    

提交回复
热议问题