天道酬勤,学无止境

比较器

The difference between comparable and comparator

Same point: 1. Comparable and comparator are used to achieve comparison between elements in a collection container, such as treeset, which are sorted according to the natural ordering of the class. The comparison algorithm is determined by the comparator itself. The difference: 1. Comparable is to make the collection element itself comparative, so that the element implements the comparable interface, and overrides the comparaeTo(T o) method to compare the order of this object with the specified object. If the object is less than, equal to, or greater than the specified object, it returns a

2021-06-01 23:35:34    分类:博客    比较器   区别   集合

Java Core API-7 (Iterator, Comparable, Comparator)

1. Iterator All Collection implementation classes implement the iterator method, which returns an object of the Iterator interface type for the convenience of iterating over collection elements. Under the java.util package.1) Iterator defines three methods:① boolean hasNext() method: Determine whether there is an element behind the pointer. ② E next () method: move the pointer backward and return the current element. E stands for generic, and the default is Object type.③void remove() method: delete the element just returned in the original collection.2) For the List collection, it can be

2021-06-01 21:30:01    分类:博客    iterator   迭代器   比较器   基础学习