comparable and comparator in java

Опубликовано: 08 Декабрь 2016
на канале: Inside App
176
2

Comparable and Comparator

Comparable and Comparator both are interfaces and can be used to sort collection elements.

But there are many differences between Comparable and Comparator interfaces that are given below.

Comparable

Comparator

1) Comparable providessingle sorting sequence. In other words, we can sort the collection on the basis of single element such as id or name or price etc.

Comparator provides multiple sorting sequence. In other words, we can sort the collection on the basis of multiple elements such as id, name and price etc.



2) Comparable affects the original class i.e. actual class is modified.

Comparator doesn't affect the original class i.e. actual class is not modified.




3) Comparable providescompareTo() methodto sort elements.

Comparator provides compare() method to sort elements.

4) Comparable is found in java.lang package.

Comparator is found in java.utilpackage.



5) We can sort the list elements of Comparable type byCollections.sort(List)method.

We can sort the list elements of Comparator type byCollections.sort(List,Comparator)method.
www.saprahits.com
#saprahits
#patelwala.com

~-~~-~~~-~~-~
Please watch: "How to online money earn from Flipkart without selling any products"
   • Video  
~-~~-~~~-~~-~


На этой странице сайта вы можете посмотреть видео онлайн comparable and comparator in java длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Inside App 08 Декабрь 2016, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 176 раз и оно понравилось 2 зрителям. Приятного просмотра!