CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.

Slides:



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

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.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Java Review Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
Chapter 19 Java Data Structures
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
COMP 103 Iterators and Iterable. RECAP  Maps and Queues TODAY  Queue Methods  Iterator and Iterable 2 RECAP-TODAY.
Java Collections Framework A presentation by Eric Fabricant.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
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.
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
1 Unit 10 - Data Structures Objectives 1. Describe the usage of data structures. 2. Develop simple data structures. 3. Apply Java collections. 4. Apply.
1 Java's Collection Framework By Rick Mercer with help from The Java Tutorial, The Collections Trail, by Joshua BlockThe Collections Trail.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
(c) University of Washington14-1 CSC 143 Java Collections.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
CSC 142 J(part 1) 1 CSC 142 The ArrayList class [Reading: chapter 10]
CSE 143 Lecture 2 More ArrayList ; classes and objects reading: 10.1; slides created by Marty Stepp and Hélène Martin
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
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.
Java 5 Part 1 CSE301 University of Sunderland Harry Erwin, PhD.
Data structures and algorithms in the collection framework 1.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
CSE 143 Lecture 2 ArrayList reading: 10.1 slides created by Marty Stepp
Practical Session 4 Java Collections. Outline Working with a Collection The Collection interface The Collection hierarchy Case Study: Undoable Stack The.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Copyright 2010 by Pearson Education Building Java Programs Chapter 10, 11 Lecture 22: 143 Preview optional reading: 10.1,
Georgia Institute of Technology What is new in Java 5.0 (1.5)? Barb Ericson Georgia Institute of Technology June 2006.
Recitation 5 Enums and The Java Collections classes/interfaces 1.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
CSE 143 Lecture 4 Exceptions and ArrayList slides created by Marty Stepp
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
More than just a song and dance.. They are objects that store primitive variable values: Integer – stores an int Double – stores a double Character –
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
University of Limerick1 Collections The Collection Framework.
1 Maps, Stacks and Queues Maps Reading:  2 nd Ed: 20.4, 21.2, 21.7  3 rd Ed: 15.4, 16.2, 16.7 Additional references: Online Java Tutorial at
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.
1 M255 Object-oriented programming with Java Prepared By: Prof. Dr. Shehab Gamalel-Din Unit 10 Collections: Sets & Maps.
Using the Java Collection Libraries COMP 103 # T2
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 19 Java Data Structures
Software Development Java Collections
JAVA COLLECTIONS LIBRARY
Week 2: 10/1-10/5 Monday Tuesday Wednesday Thursday Friday
Road Map CS Concepts Data Structures Java Language Java Collections
Road Map CS Concepts Data Structures Java Language Java Collections
Welcome to CSE 143!.
Java Collections Overview
Can store many of the same kind of data together
Wrapper Classes The java.lang package contains wrapper classes that correspond to each primitive type: Primitive Type Wrapper Class byte Byte short Short.
Words exercise Write code to read a file and display its words in reverse order. A solution that uses an array: String[] allWords = new String[1000]; int.
Welcome to CSE 143!.
Welcome to CSE 143! Go to pollev.com/cse143.
Can store many of the same kind of data together
CSE 1020: The Collection Framework
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
Parsing JSON, Using Libraries, Java Collections, Generics
slides created by Alyssa Harding
Presentation transcript:

CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu

Today’s Topic Java Collection Interface Generics Collections Usage Wrapper Class CSE 142/143 Collections Review List & Set Stack & Queue Map

Java Collection Interface Interface is just a type Learn how to look up Java Documentation of the standard library What are the basic operations? llection.html llection.html Iterable and Comparable To use for loop and define the rule how object stored is compared Not used in HW5, but good to know

Collections Declaration with Generic Types How? List v = new ArrayList (); List e = new ArrayList (); Can we construct List ArrayList ? NO! In Java, anything that is used as generics has to be convertible to Object Solution: Use Wrapper Class for primitive types. E.g. ArrayList Every primitive type has a corresponding wrapper class: Integer for int, Double for double, Character for char, Boolean for boolean, And so on BTW.. String is not a primitive type and String objects are immutable (Continue on next slide)

Collections Declaration with Generic Types Autoboxing and Unboxing Java will automatically "box" the ints for us (i.e., wrap them up in Integer objects) Java automatically "unboxes" the values for you, unwrapping the Integer objects and giving you the ints that are contained inside. List numbers1 = new ArrayList (); numbers.add(18); numbers.add(34); int product = numbers.get(0) * numbers.get(1);

Lists & Sets Difference? Sets don’t allow duplicates Client can control order over lists, no index (How to remove?) HashSet doesn’t keep order TreeSet keeps things in sorted order APIs List: Set: Different Types and their Tradeoffs List ArrayList LinkedList Set HashSet(fast) TreeSet Declaration: LinkedList l = LinkedList (); is not good style should be List l = LinkedList (); You can find all of them in JAVA API!

Stack & Queue Discussed in CSE373 APIs Stack Class: Stack s = new Stack (); Queue Interface: Queue q = new LinkedList ();

Map Dictionary that stores key/value pairs One to one relation Map can have two types.You can have V as Lists or other data structures E.g. Map > API: TreeMap and HashMap

Useful Info ArrayList vs. Linked List linkedlist-over-arraylist HashSet vs. TreeSet treeset Some material of this slide is credited to Stuart Reges’ CSE143 Notes