Sorting ArrayList

后端 未结 6 963
我在风中等你
我在风中等你 2021-01-25 19:19

Since I\'m just starting with JAVA, I\'m curious what is the best option for implementing sorting in JAVA (for ArrayLists). Below I provide my PHP code.

public i         


        
6条回答
  •  Happy的楠姐
    2021-01-25 20:14

    The way to do this would be to use Collections class, and call Collections.sort(java.util.List, java.util.Comparator) on your list. It is documented here. The Comparator here is an interface that you would need to implement in order to do a custom sort. To implement the Comparator interface you need to provide implementations for

    int compare(T o1,T o2) and boolean equals(Object obj).

    using the logic you already have in your PHP file.

提交回复
热议问题