跳到主要內容

Comparable 與 Comparator



如果想針對陣列進行排序,可以使用java.util.Arrays的sort()方法,如果你查詢API文件,會發現該方法針對物件排序時有兩個版本,一個是你收集在陣列中的物件必須是Comparable(否則會拋出ClassCastException),另一個版本則可以傳入Comparator指定排序方式。

https://openhome.cc/Gossip/Java/ComparableComparator.html

留言

這個網誌中的熱門文章

Benefits of logging progress

Logging your experience has important benefits: Working through the steps will keep you from getting stalled. As a cohort you will build up a useful body of information that others can learn from. You will have a chance to find other students working on similar challenges, allowing you to collaborate.