Comparing things Comparable & Comparator.

Slides:



Advertisements
Similar presentations
CALCULATOR MANIPULATION. Due to the differences in calculators you will have to be able to use your own effectively.
Advertisements

Alternative approach to path construction Andrew Williams
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Combining Integers What is an Integer? (No decimals – No Fractions) Negative numbers Positive numbers Zero.
How to Recall after Submitting a Tk20 Assignment Use this when you submitted the wrong document to an assignment and need to submit a different or more.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
The Java Collections Framework By the end of this lecture you should be able to: use the ArrayList class to store a list of objects; use the HashSet class.
Introduction We are going to look at exponential functions We will learn about a new ‘special’ number in Mathematics We will see how this number can be.
Adding SubtractingMultiplyingDividingMiscellaneous.
Instructions To use this Powerpoint resource please follow these steps: 1.Select which slide(s) you would like to use. 2.Right-click on the slide, under.
BIG NUMBERS and SMALL NUMBERS (Scientific Notation)
Instructions To use this Powerpoint resource please follow these steps: 1.Select which slide(s) you would like to use. 2.Right-click on the slide, under.
Polymorphism SWE 619. Outline equals() Revisiting Liskov’s mutable vs. not rule Polymorphism Uniform methods for different types “easy” polymorphism Element.
Figure out how to work with infinite series when i=0 vs i=1 Slide 12.
This is going to be a chasing game were the mi6 have to catch the hackers They should be able to catch them in this quick car and little kids like quick.
Instructional Technique #2 Use Explicit Instruction to Convey Critical Content.
BUYING TIME TO THINK What is “buying time”? Why is it important? How can you “buy time” before answering a question? Copyright © 2015 The Teacher Writing.
Global Dimension & Climate Change
Would you agree with this?
Adjectival phrases You already know how to add adverbial clauses.
Goal Setting 2nd Grade ICAP
How to critique a journal article
Subtraction by counting on
The things you need to know to get your gradebook going again!!
Dangling modifiers.
The Exponential and Log Functions
Road Map CS Concepts Data Structures Java Language Java Collections
Important Information
Interview with an Endangered Species
Shortcuts in Addition By Monica Yuskaitis.
WWB Training Kit #18 Logical Consequences.
Module 5 Topic D.
Part of the Collections Framework
I am comparing humans to a(n) (type animal here)
Earley’s Algorithm (1970) Nice combo of our parsing ideas so far:
This little presentation comes from the folks at Sparky Teaching.
תירגול 9 אובייקטים.
Equivalent Equations Objectives: Student will be able to identify equivalent equations and construct equivalent equations.
Today’s Question: What’s the difference between a direct metaphor and an implied metaphor? (And why do we care?)
Using Schedule Planner in OASIS
Venn Diagrams to find the HCF and LCM
3.1 Iteration Loops For … To … Next 18/01/2019.
Five Forbidden Phrases
Using Schedule Planner in OASIS
CSE 1020: The Collection Framework
Picture This! Fractions and Wholes.
Adding Fast Nines.
Adding with 9’s.
Adding with 10’s.
Hi, there.
YOUR text YOUR text YOUR text YOUR text
½ of 6 = 3.
Insert Presentation Title Here Insert Presentation Summary Here
Today we will understand how to add and subtract negative numbers
The Right Kind of Information Silos
Trees in java.util A set is an object that stores unique elements
FM2 Section A Planning Workshop
Which option did you chose?
you get to solve puzzles!
Adding ____ + 10.
CONTENTS     Enter text Enter text Enter text Enter text
HFOOAD Chapter 5 Interlude
b c b b 30 20 15 a a a Create one of your own… b b c
PLEASE ADD YOUR TITLE HERE.
Feeling Worried – your experience
How to send your Youtube link...
Production/Operations​
Your name Your organization Your
Today Binary addition Representing negative numbers 2.
Presentation transcript:

Comparing things Comparable & Comparator

Maybe we are jumping the gun a bit here but please live with it for a while. We are wanting to implement a set of “things” of the same class obviously  A set disallows duplicates. So, when we add something to the set we must make sure it is not already in the set. Consequently we need to be able to compare “things”. There are, broadly, 2 ways to do this

preliminaries We are going to use two classes from java.util TreeSet HashSet

TreeSet

HashSet

Comparable

Comparable We want to create a set of people (class Person) where a Person has a first and second name

Comparable

Comparable

Comparable

Comparable It’s comparable

Comparable x.compareTo(y)

Comparable

Comparable Duplicate not added

Comparable Same again but Species rather than Person

Comparable Duplicate avoided

Comparator

Comparator We now look at an alternative, the Comparator, an object that is used to make comparisons Our example uses cars

Comparator

Comparator

Comparator

Comparator

Comparator

Comparator Duplicate omitted

Comparator

Comparator Why do we get duplicates?

HashSet v TreeSet

HashSet doesn’t allow us to use Comparable or Comparator Why?