Collections class Method name Description binarySearch(list, value)

Slides:



Advertisements
Similar presentations
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
Advertisements

Computer Science 209 Software Development Equality and Comparisons.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 11: Sorting and Searching  Searching Linear Binary  Sorting.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
Binary Search Trees CMSC 132 Chapter 8.1 Nelson Padua-Perez Bill Pugh.
1 L42 Collections (2). 2 OBJECTIVES  To use collections framework algorithms to manipulate  search  sort  and fill collections.
Unit 301 Java Collections Framework: Classes I JCF Class Hierarchy The ArrayList Class The Collections Class.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 24 : Collections King Fahd University of Petroleum & Minerals College of Computer.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 17 Advanced Java Concepts Data Structure Support.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Introduction to Searching and Sorting
Building Java Programs Interfaces, Comparable reading: , 16.4, 10.2.
1 CSC 222: Object-Oriented Programming Spring 2013 Java interfaces & polymorphism  Comparable interface  defining an interface  implementing an interface.
CSE 143 Lecture 15 Binary Search; Comparable reading: 13.2; 10.2 slides created by Marty Stepp
Collections –data structures and Algorithms L. Grewe.
1.0tCopyright © 1998 Purple Technology, Inc. 1 Java Collections Framework Authored by Alex Chaffee Copyright © 1998 Purple Technology, Inc. All rights.
The Java Collections Framework Based on
Java 2 Collections Bartosz Walter Software Engineering II.
©SoftMoore ConsultingSlide 1 Java Collections Framework.
CSE 143 Lecture 2 More ArrayList ; classes and objects reading: 10.1; slides created by Marty Stepp and Hélène Martin
Binary search and complexity reading:
University of Limerick1 Collections The Collection Framework.
1 CSE 331 Comparing objects; Comparable, compareTo, and Comparator slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R.
Building Java Programs Chapter 13 Searching and Sorting Copyright (c) Pearson All rights reserved.
Building Java Programs Chapter 13 Sorting reading: 13.3, 13.4.
Searching and Sorting.
Lecture 23:More on Interfaces
Lecture 13: Interfaces, Comparable reading: , 16.4, 10.2
Chapter 19 Java Data Structures
Collections.
Wednesday Notecards What’s your credit card number?
slides created by Marty Stepp and Hélène Martin
CSE 143 Lecture 14 Searching and Comparable reading: ; 10.2
Introduction to Searching and Sorting
Lecture 14: binary search and complexity reading:
TCSS 143, Autumn 2004 Lecture Notes
Generics and Type Parameters
Building Java Programs
slides adapted from Marty Stepp and Hélène Martin
Building Java Programs
Programming in C# Comparison (Sorting)
The compareTo interface
Lecture 15: binary search reading:
CSE 154 Sorting reading: 13.3, 13.4
Ben’s Lecture Cliff Notes
Collections in Java The objectives of this lecture are:
slides created by Marty Stepp
Collections class Method name Description binarySearch(list, value)
CSE 143 Lecture 16 (A) Searching and Comparable
Shapes Consider the task of writing classes to represent 2D shapes such as Circle, Rectangle, and Triangle. Certain operations are common to all shapes:
Compiler Design Second Lecture.
slides created by Marty Stepp and Ethan Apter
slides created by Marty Stepp
CSE 143 Sorting reading: 13.3, 13.4.
Lexical Ordering and Sorting
Building Java Programs Chapter 13
The Comparable Interface
Binary search (13.1) binary search: Locates a target value in a sorted array/list by successively eliminating half of the array from consideration. How.
slides created by Marty Stepp and Hélène Martin
CSE 373 Data Structures and Algorithms
CSE 373 Sorting 1: Bogo Sort, Stooge Sort, Bubble Sort
Podcast Ch22a Title: Array-based Binary Trees
CSE 143 Lecture 8 Iterators; Comparable reading: 11.2; 10.2
Collections class Method name Description binarySearch(list, value)
CSE 373: Data Structures and Algorithms
slides adapted from Marty Stepp and Hélène Martin
CSE 143 Lecture 14 Searching and Comparable reading: ; 10.2
RANDOM NUMBERS SET # 1:
CSE 373: Data Structures and Algorithms
Presentation transcript:

Collections class Method name Description binarySearch(list, value) returns the index of the given value in a sorted list (< 0 if not found) copy(listTo, listFrom) copies listFrom's elements to listTo emptyList(), emptyMap(), emptySet() returns a read-only collection of the given type that has no elements fill(list, value) sets every element in the list to have the given value max(collection), min(collection) returns largest/smallest element replaceAll(list, old, new) replaces an element value with another reverse(list) reverses the order of a list's elements shuffle(list) arranges elements into a random order sort(list) arranges elements into ascending order

The compareTo method (10.2) The standard way for a Java class to define a comparison function for its objects is to define a compareTo method. Example: in the String class, there is a method: public int compareTo(String other) A call of A.compareTo(B) will return: a value < 0 if A comes "before" B in the ordering, a value > 0 if A comes "after" B in the ordering, 0 if A and B are considered "equal" in the ordering.

Comparable (10.2) public interface Comparable<E> { public int compareTo(E other); } A class can implement the Comparable interface to define a natural ordering function for its objects. A call to your compareTo method should return: a value < 0 if the this object comes "before" other one, a value > 0 if the this object comes "after" other one, 0 if the this object is considered "equal" to other.