Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal

Slides:



Advertisements
Similar presentations
Java Programming: Advanced Topics 1 Collections and Utilities.
Advertisements

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Data Structures and Collections
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
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.
Professor Evan Korth (adapted from Sun’s collections documentation)
Algorithm Programming Containers in Java Bar-Ilan University תשס " ו by Moshe Fresko.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Data Structures & Java Collections Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 17 Advanced Java Concepts Data Structure Support.
Chapter 19 Java Data Structures
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
Java's Collection Framework
Collections. Why collections? Collections are used to hold a collection of objects. List holds objects based on order of insertion and can hold non unique.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
CS Collection and Input/Output Classes CS 3331 Fall 2009.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities Chapter 4.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
1 Java's Collection Framework By Rick Mercer with help from The Java Tutorial, The Collections Trail, by Joshua BlockThe Collections Trail.
(c) University of Washington14-1 CSC 143 Java Collections.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Big Java Chapter 16.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Collections. The Plan ● Why use collections? ● What collections are available? ● How are the collections different? ● Examples ● Practice.
Chapter 18 Java Collections Framework
Computer Science 209 Software Development Java Collections.
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Collections –data structures and Algorithms L. Grewe.
Data structures and algorithms in the collection framework 1.
The Java Collections Framework Based on
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
16-August-2002cse Libraries © 2002 University of Washington1 Class Libraries CSE 142, Summer 2002 Computer Programming 1
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.
Collections Mrs. C. Furman April 21, Collection Classes ArrayList and LinkedList implements List HashSet implements Set TreeSet implements SortedSet.
13 Collections Framework. 2 Contents What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map.
More Java: Static and Final, Abstract Class and Interface, Exceptions, Collections Framework 1 CS300.
Nov 22, 2010IAT 2651 Java Collections. Nov 22, 2010IAT 2652 Data Structures  With a collection of data, we often want to do many things –Organize –Iterate.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
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.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
CS202 Java Object Oriented Programming Introduction to Collection Classes Chengyu Sun California State University, Los Angeles.
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Chapter 19 Java Data Structures
Software Development Java Collections
University of Central Florida COP 3330 Object Oriented Programming
Road Map CS Concepts Data Structures Java Language Java Collections
Java Collections Overview
14.1 The java.util Package.
Collections Framework
CSE 1020: The Collection Framework
Presentation transcript:

Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal

Recap Assignment 08 File input/output

Today Assignment 9 Data structures Thinking in Java – Chapter 11

Collections We need to give a meaningful structure to the data Array is a basic structure We mentioned java.util.Vector Some common structes exist that programmers often make use of. Each is an analogy for a real world situation. Örnekler: –Bag –Heap –Set –List –Queue –Table –Tree

java.util.* Java 2 "Collections" – A "framework" (iskelet) –Interfaces (Kontratlar) Collection, Set, Map, etc. –Implementations (Uygulamaları) TreeMap, LinkedList, ArrayList, etc. –Older classes that existed in Java 1.1 Vector, Hashtable –Helper classes Arrays, Iterator, etc. –Algorithms Sort, etc.

Interfaces (Kontratlar) Defines the type of data structure –3 Main Types Set: No duplicate elements allowed List: Can have duplicates, order is important Map: Elements are recalled based on an index

Interfaces (Kontratlar) 6 interfaces in total –Collection (general groupings) Set(elements are important – can be ordered) List(order is the determining factor) SortedSet(a set that is kept in order based on a comparing method. [Comparator]) –Map (matching of an element to a unique ‘key’ for later retrieval) SortedMap(collection that is ordered by the key)

Classes Implementation Type HashTable Variable sized Array Balanced Tree Linked list Interface Set HashSetTreeSet List ArrayListLinkedList Map HashMapTreeMap

Set Classes HashSet –A structure that stores elements using a hashtable algorithm. Fastest set. TreeSet –A sorted set implementation using a "Red-Black" sorting algorithm.

Examples - Sets import java.util.*; HashSet toolBox = new HashSet(); toolBox.add(“hammer"); toolBox.add(“screwdriver"); toolBox.add(“pliers"); if ( !toolBox.isEmpty() ) println( toolBox.size() ); println ( toolBox );

List Classes ArrayList –Similar to a Vector. An automatically resizable Array implementation. LinkedList –“Doubly linked list” implementation where given an element you can access the previous and next elements. Useful in modelling queues.

Example - Lists import java.util.*; ArrayList attendance = new ArrayList(); attendance.add("Ali Durmaz"); attendance.add("Veli Kaymaz"); attendance.add("Ayşe Kaçmaz"); for (i=0; i< attendance.size(); i++) println(attendance.get(i) );

Map Classes HashMap –An implementation where keys are stored and retrieved using a hastable. Fast. TreeMap –A SortedMap implementation that keeps keys ordered using a "Red-Black" sorting algorithm.

Example - Maps import java.util.*; HashMap team = new HashMap(); team.put(“defender", “Emre"); team.put(“goalie", “Kadir"); team.put(“striker", “Lale"); if ( ! team.containsKey(“midfielder") ) team.put(“midfielder", “Mustafa");

Helper classes Arrays –Static methods Searching, sorting, comparison, populating, etc. Basic usage –Iterator –Comparator –Exceptions

Iterator Mechanism that allows us to examine the elements stored in a data structure one by one. –The iterator() that exists in all collections returns an iterator that we can use. –Iterator only has three methods Object next() boolean has next() void remove() ListIterator –Has additional methods that are suitable for lists. int nextIndex() void set(Object o) boolean hasPrevious() …

Example - Iterator import java.util.*; Iterator i = attendance.iterator(); while ( i.hasNext() ) System.out.println( i.next() );

Generics – Java 1.5 Previously a collection had no idea what Type (the class they belonged to) of elements it was storing. Java 1.5 provides “generics”. Through this mechanism, the compiler guarantees that the program uses the correct classes.

Generics – example ArrayList attendance = new ArrayList (); attendance.add("Ali Durmaz"); attendance.add("Veli Kaymaz"); attendance.add(new Integer(25)); //error!! for (i=0; i< attendance.size(); i++) println(attendance.get(i) ); Iterator i = attendance.iterator(); while ( i.hasNext() ) System.out.println( i.next() );

Assignment 10 Rewrite the ShapeApplicaitons you have developed for assignment 07, using Collections. –Choose a collection for Shapes –Choose a group for colors –etc. Hint: Make use of Comparator to simplify sorting...

Next week Interfaces and beyond