Java Collection Classes Com379PT

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 5 The Collections API.
Advertisements

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Lecture 3 Introduction to Collections Advanced Java Programming 1 dr inż. Wojciech Bieniecki
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.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 7 Object Oriented Programming in Java Advanced Topics Collection.
15-Jun-15 Lists in Java Part of the Collections Framework.
1 L41 Collections (1). 2 OBJECTIVES  What collections are.  To use class Arrays for array manipulations.  To use the collections framework (prepackaged.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 24 : Collections King Fahd University of Petroleum & Minerals College of Computer.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
Unit 291 Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
Chapter 101 Dynamic Data Structures and Generics Chapter 10.
The Java Collections Package C. DeJong Fall 2001.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Advanced Java Session 3 New York University School of Continuing and Professional Studies.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Recitation 1 CS0445 Data Structures Mehmud Abliz.
AP CS Workshop ArrayList It is very common for applications to require us to store a large amount of data. Array lists store large amounts of data.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
CIS 644 Aug. 25, 1999 tour of Java. First … about the media lectures… we are experimenting with the media format please give feedback.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
COLLECTIONS Byju Veedu s/Collection.html.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Collections –data structures and Algorithms L. Grewe.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
Collection 105 Yola. To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps.
CS-2852 Data Structures LECTURE 7A Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Generics and Collections Course Lecture Slides 19 th July 2010 “Never.
1 Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain:
1 Interfaces in Java’s Collection Framework Rick Mercer.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
13 Collections Framework. 2 Contents What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
CS Ananda Gunawardena.  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Introduction to Computational Modeling of Social Systems Prof. Lars-Erik Cederman Center for Comparative and International Studies (CIS) Seilergraben 49,
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
Data Structures I Collection, List, ArrayList, LinkedList, Iterator, ListNode.
1 Copyright © 2011 Tata Consultancy Services Limited COLLECTIONS By TEAM 5 Rajendhiran Sivan Christi Yashwanth Bijay Smruthi Satyajit.
University of Limerick1 Collections The Collection Framework.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
IMPLEMENTATION OF CLASS EXTENT by Paweł Świetlicki.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 20 Lists, Stacks, Queues, and Priority Queues
University of Central Florida COP 3330 Object Oriented Programming
Object-Oriented Programming Paradigm
14.1 The java.util Package.
Collections Not in our text.
Programming Languages
Introduction to Collections
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Web Design & Development Lecture 6
Presentation transcript:

Java Collection Classes Com379PT

Collection Classes  A collection is a grouping of objects of the same class or sub class Java.util package LinkedList  Generic linked list ArrayList  Generic dynamic Array

What are Collections?  Collections represent data items that should be naturally grouped A poker hand (collection of cards) A mail folder (collection of letters) A telephone directory (a collection of name to phone number mappings)

LinkedList & ArrayList  Two types of Collection class  Are used in the same way as each other: MethodDescription void add(Object o)Add o to the end of the list void add(int I, Object o)Add to the i’th position object o Object get(int i)Return the i’th object in the list int size()Return the size of the list  Note the type Object is used. All classes extend Object.

Collections Framework  All collection frameworks contain:  Interfaces – Allow collections to be manipulated independently of their representation.  Implementations – Implementations of the collection interfaces.  Algorithms – Methods for performing searches and sorting.

Collection example

Collection Types  Array  List Vector ArrayList Queue  Associative Array Hashtable  + More

ArrayList – Collection example public class Student { private String name; public Student(String aName) { this.name = aName; } public String getName() { return name; }

ArrayList – Collection example import java.util.ArrayList; public class Course { private ArrayList studentList = new ArrayList(10); private Student aStudent; public void addStudent(String aName) { studentList.add(new Student(aName)); } public Student getStudent() { aStudent = (Student)studentList.get(0); return aStudent; }

ArrayList – Collection example public class TestCourse { public static void main(String [] args) { Course com379 = new Course(); com379.addStudent("John"); Student temp = com379.getStudent(); System.out.println("Name: " + temp.getName()); }

Casting  Passing one object off as another  When creating a collection the default type is of Object  When returning one of the position in the list it is returned of type object  aStudent = (Student)studentList.get(0);

Iterating through the list  If we have predefined our size we may have some empty elements  To list all available elements we can iterate Iterator it = list.iterator(); while (it.hasNext()) { Student aStudent = (Student)it.next(); System.out.println(aStudent.toString()); }

Why use collections?  It reduces programming effort? Provides useful data structures Allows you to concentrate in the working of the code  Allows interoperability among unrelated API’s If your communication API has a collection of IP’s and my GUI API displays in TABS IP’s then they can work together even though they were written separately