---
title: "Difference between comparable and comparator in java"  
description: "Difference between comparable and comparator in java"  
author: "Anonymous User"  
published: 2015-07-28  
updated: 2015-07-28  
canonical: https://www.mindstick.com/forum/23382/difference-between-comparable-and-comparator-in-java  
category: "java"  
tags: ["java", "collection"]  
reading_time: 1 minute  

---

# Difference between comparable and comparator in java

What is the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) between [Comparable](https://www.mindstick.com/interview/2521/what-is-the-difference-between-comparable-and-comparator) and comparator on [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)

## Replies

### Reply by Anonymous User

**Comparable**\
1) Comparable provides single sorting sequence. In other words, we can sort the collection on the basis of single element such as id or name or price etc. 2) Comparable affects the original class i.e. actual class is modified.3) Comparable provides compareTo() method to sort elements. 4) Comparable is found in java.lang package. .5) We can sort the list elements of Comparable type by Collections.sort(List) method. \
**Comparator**\
1)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)Comparator doesn't affect the original class i.e. actual class is not modified.3) Comparator provides compare() method to sort elements.4) Comparator is found in java.util package5) We can sort the list elements of Comparator type by Collections.sort(List,Comparator) method.


---

Original Source: https://www.mindstick.com/forum/23382/difference-between-comparable-and-comparator-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
