---
title: "Comparison Shopping: Using Comparable and Comparator to Sort Java Objects"
description: "This tutorial is for intermediate-level Java developers who want to add comparison and sorting capabilities to the custom classes they’ve created for their projects."
canonical: https://www.vidyasource.com/tutorials/comparison-shopping/
type: tutorial
published: 2013-10-27
tags: ["Java", "programming", "sorting", "comparator", "comparable", "function"]
image: https://www.vidyasource.com/img/tutorials/car-shopping.jpg
---

# Comparison Shopping: Using Comparable and Comparator to Sort Java Objects

> This tutorial is for intermediate-level Java developers who want to add comparison and sorting capabilities to the custom classes they’ve created for their projects.

- Canonical page: https://www.vidyasource.com/tutorials/comparison-shopping/
- Structured data (JSON-LD): https://www.vidyasource.com/tutorials/comparison-shopping.json
- Published: 2013-10-27
- Topics: Java, programming, sorting, comparator, comparable, function
- Video: https://www.youtube.com/watch?v=pq0ArQhhWzU
- Source code: https://github.com/VidyaSource/comparison-shopping

This tutorial is for intermediate-level Java developers who want to add comparison and sorting capabilities
to the custom classes they’ve created for their projects.

---

Vidya is a certified small business in Northern Virginia that modernizes legacy systems, builds enterprise AI, and designs cloud and data architecture for commercial companies and federal agencies. Vidya documents its delivered engagements in case studies and publishes courses, tutorials, and articles for engineers and the people who lead them. The company name is Vidya. Its website is vidyasource.com. Start at https://www.vidyasource.com/llms.txt for the index of everything Vidya publishes, or https://www.vidyasource.com/contact/ to talk to Vidya.
