Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 24 : Collections King Fahd University of Petroleum & Minerals College of Computer.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 4 : Polymorphism King Fahd University of Petroleum & Minerals College of Computer.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Generics and the ArrayList Class
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 23 : Generics King Fahd University of Petroleum & Minerals College of Computer Science.
Slides prepared by Rose Williams, Binghamton University ICS201 Exception Handling University of Hail College of Computer Science and Engineering Department.
Chapter 16 Collections, Maps and Iterators Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
COE 485 Senior Design Project Group # 5 Week 8 Term 042 King Fahd University of Petroleum and Minerals College of Computer Science and Engineering Computer.
Using ArrayList. Lecture Objectives To understand the foundations behind the ArrayList class Explore some of the methods of the ArrayList class.
Java Collections. Lecture Objectives To understand the concepts of Java collections To be able to implement Java programs based on Collections.
Slides prepared by Rose Williams, Binghamton University Chapter 14 Generics and the ArrayList Class.
Chapter 14 Generics and the ArrayList Class Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Slides prepared by Rose Williams, Binghamton University ICS201 Lectures 18 : Threads King Fahd University of Petroleum & Minerals College of Computer Science.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
Introduction to Searching and Sorting
1 Introduction to Searching and Sorting Comparable Interface -Reading p Comparator Interface.
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 9 : Exception Handling King Fahd University of Petroleum & Minerals College of Computer.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
CMSC 202 Generics. Nov Generalized Code One goal of OOP is to provide the ability to write reusable, generalized code. Polymorphic code using.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Generics and Collections. Introduction Generics New feature of J2SE 5.0 Provide compile-time type safety Catch invalid types at compile time Generic methods.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 13 : Swing I King Fahd University of Petroleum & Minerals College of Computer Science.
Chapter 14 Generics and the ArrayList Class Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
15440 Distributed Systems Recitation 1 Objected-Oriented Java Programming.
The Java Collections Framework Based on
Java 2 Collections Bartosz Walter Software Engineering II.
Introduction to Generics
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 14 : Swing II King Fahd University of Petroleum & Minerals College of Computer Science.
CSE 1201 Object Oriented Programming ArrayList 1.
Slides prepared by Rose Williams, Binghamton University Chapter 16 Collections and Iterators.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
Chapter 13 Interfaces and Inner Classes Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights reserved.
University of Limerick1 Collections The Collection Framework.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Comp 248 Introduction to Programming Chapter 6 Arrays Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University,
ICS102 Lecture 8 : Boolean Expressions King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Java Collection Classes Com379PT
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
Java Generics. Lecture Objectives To understand the objective of generic programming To be able to implement generic classes and methods To know the limitations.
Lecture 13: Interfaces, Comparable reading: , 16.4, 10.2
Arrays 3/4 By Pius Nyaanga.
Wednesday Notecards What’s your credit card number?
Collections class Method name Description binarySearch(list, value)
TCSS 143, Autumn 2004 Lecture Notes
CMSC 202 Interfaces.
Object-Oriented Programming Paradigm
Comp 249 Programming Methodology
Object Oriented Programming in java
Collections class Method name Description binarySearch(list, value)
Shapes Consider the task of writing classes to represent 2D shapes such as Circle, Rectangle, and Triangle. Certain operations are common to all shapes:
Containers and Iterators
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
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.
Collections class Method name Description binarySearch(list, value)
Arrays 3/4 June 3, 2019 ICS102: The course.
Chapter 6 Arrays.
CMSC 202 Interfaces.
Presentation transcript:

Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 24 : Collections King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department

Collections A Java collection is any class that holds objects and implements the Collection interface For example, the ArrayList class is a Java collection class, and implements all the methods in the Collection interface Collections are used along with iterators The Collection interface is the highest level of Java's framework for collection classes All of the collection classes discussed here can be found in package java.util

The Collection Landscape

Wildcards Classes and interfaces in the collection framework can have parameter type specifications that do not fully specify the type plugged in for the type parameter Because they specify a wide range of argument types, they are known as wildcards public void method(String arg1, ArrayList arg2) In the above example, the first argument is of type String, while the second argument can be an ArrayList with any base type

Wildcards A bound can be placed on a wildcard specifying that the type used must be an ancestor type or descendent type of some class or interface The notation specifies that the argument plugged in be an object of any descendent class of String The notation specifies that the argument plugged in be an object of any ancestor class of String

The Collection Framework The Collection interface describes the basic operations that all collection classes should implement The method headings for these operations are shown on the next several slides Since an interface is a type, any method can be defined with a parameter of type Collection That parameter can be filled with an argument that is an object of any class in the collection framework

Collection Interface methods

Method Headings in Collection

Collection Relationships There are a number of different predefined classes that implement the Collection interface Programmer defined classes can implement it also A method written to manipulate a parameter of type Collection will work for all of these classes, either singly or intermixed There are two main interfaces that extend the Collection interface: The Set interface and the List interface

Collection Relationships Classes that implement the Set interface do not allow an element in the class to occur more than once The Set interface has the same method headings as the Collection interface, but in some cases the semantics (intended meanings) are different Methods that are optional in the Collection interface are required in the Set interface

Collection Relationships Classes that implement the List interface have their elements ordered as on a list Elements are indexed starting with zero A class that implements the List interface allows elements to occur more than once The List interface has more method headings than the Collection interface Some of the methods inherited from the Collection interface have different semantics in the List interface The ArrayList class implements the List interface

Methods in the Set Interface

Methods in the List Interface (Part 1 of 16)

Methods in the List Interface (Part 2 of 16)

Methods in the List Interface (Part 3 of 16)

Methods in the List Interface (Part 4 of 16)

Methods in the List Interface (Part 7 of 16)

Methods in the List Interface (Part 9 of 16)

Methods in the List Interface (Part 10 of 16)

Methods in the List Interface (Part 12 of 16)

Methods in the List Interface (Part 13 of 16)

Methods in the List Interface (Part 14 of 16)

Methods in the List Interface (Part 15 of 16)

Comparison

The Collections Class The Collections class is a utility class. It contains static methods for manipulating collection objects. The Arrays class is also a utility class. It contains static methods for manipulating arrays. One useful method used is asList() to convert an array into a list. The following are the most frequently used methods of the Collections class. static int binarySearch(List list, Object o) static int binarySearch(List list, Object o, Comparator c) static void sort(List list) static void sort(List list, Comparator c) static Object max(Collection c) static Object min(Collection c) static void reverse(List list) static void shuffle(List list)

The end