CompSci 100e2.1 Today’s Topics l Reading:  Sedgewick & Wayne: 1.1-1.4, 2.1- 2.2 l Topics  APTs  Basic Collections: ArrayLists: the expandable array.

Slides:



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

Processing Data in Collections Chapter Object Wrappers Collections can only hold objects. Primitive types ( int, double, float, etc.) are not objects.
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Java Collections. Lecture Objectives To understand the concepts of Java collections To be able to implement Java programs based on Collections.
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
CS2110 Recitation 07. Interfaces Iterator and Iterable. Nested, Inner, and static classes We work often with a class C (say) that implements a bag: unordered.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CompSci 100E Gambler's Ruin  One approach. Monte Carlo simulation.  Flip digital coins and see what happens. o Pseudorandom number generation ojava.util.Random.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
CS1101: Programming Methodology Aaron Tan.
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.
Collections F The limitations of arrays F Java Collection Framework hierarchy  Use the Iterator interface to traverse a collection  Set interface, HashSet,
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
ITEC 2620A Introduction to Data Structures
(c) University of Washington14-1 CSC 143 Java Collections.
Lecturer: Dr. AJ Bieszczad Chapter 11 COMP 150: Introduction to Object-Oriented Programming 11-1 l Basics of Recursion l Programming with Recursion Recursion.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Big Java Chapter 16.
Not overriding equals  what happens if you do not override equals for a value type class?  all of the Java collections will fail in confusing ways 1.
2-1 Week 2 Sets Set concepts (you should know these!) Set applications. A set ADT (abstract data type): requirements, contract. Implementations of sets:
111 © 2002, Cisco Systems, Inc. All rights reserved.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
2.1 Functions Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · October 21, 2015.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
Building Java Programs Chapter 11 Lecture 11-1: Sets and Maps reading:
Chapter 18 Java Collections Framework
Sets, Maps and Hash Tables. RHS – SOC 2 Sets We have learned that different data struc- tures have different advantages – and drawbacks Choosing the proper.
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
2.1 Functions Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · 9/10/08 9/10/08.
CompSci 100E Functions (Static Methods)  Java function.  Takes zero or more input arguments.  Returns one output value.  Applications.  Scientists.
Recap of Functions. Functions in Java f x y z f (x, y, z) Input Output Algorithm Allows you to clearly separate the tasks in a program. Enables reuse.
2.2 Libraries and Clients Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · December.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
The Math Class Methods Utilizing the Important Math Operations of Java!
1.2 Built-in Types of Data Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · December.
1 Introduction  Algorithms  Data structures  Abstract data types  Programming with lists and sets © 2008 David A Watt, University of Glasgow Algorithms.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
Maps Nick Mouriski.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
CS1020 Data Structures and Algorithms I Lecture Note #6 Vector and ArrayList.
Interfaces. In order to work with a class, you need to understand the public methods  methods, return types,…  after you instantiate, what can you do.
CPS 100e 5.1 Inheritance and Interfaces l Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape, …
Lecture 9:FXML and Useful Java Collections Michael Hsu CSULA.
CS202 Java Object Oriented Programming Introduction to Collection Classes Chengyu Sun California State University, Los Angeles.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Slides by Donald W. Smith
Sections 10.5 – 10.6 Hashing.
Jeff Forbes Owen Astrachan September 8, 2017
Using the Java Collection Libraries COMP 103 # T2
Data Structures 1st Week
Sets Set is an unordered list of items
Week 2: 10/1-10/5 Monday Tuesday Wednesday Thursday Friday
Sets, Maps and Hash Tables
CS2110: Software Development Methods
CSE 1020: The Collection Framework
slides created by Marty Stepp
Java Basics – Arrays Should be a very familiar idea
Presentation transcript:

CompSci 100e2.1 Today’s Topics l Reading:  Sedgewick & Wayne: , l Topics  APTs  Basic Collections: ArrayLists: the expandable array Sets: the list of distinct elements l Acknowledgements  Slides from Sedgewick & Wayne

CompSci 100e2.2 Tips for Excelling in CompSci 100e l Read the Book l Ask questions l Keep working until it is correct l Seek help when stuck l Visit the professor, TA, and UTAs l Start early! l Get the easy points

CompSci 100e2.3 3 Functions (Static Methods) l Java function.  Takes zero or more input arguments.  Returns one output value. l Applications.  Scientists use mathematical functions to calculate formulas.  Programmers use functions to build modular programs.  You use functions for both. l Examples.  Built-in functions: Math.random(), Math.abs(), Integer.parseInt().  Book libraries StdDraw.show(), StdAudio.play().  User-defined functions: main().

CompSci 100e2.4 4 Anatomy of a Java Function l Java functions. Easy to write your own. f(x) =  x input … output

CompSci 100e2.5 Libraries l Library. A module whose methods are primarily intended for use by many other programs. l Client. Program that calls a library. l API. Contract between client and implementation. l Implementation. Program that implements the methods in an API.

CompSci 100e2.6 Algorithmic Programming Testing l Algorithmic Programming Testing problems (APTs)  Assigned most weeks, due on Tuesdays  Similar to Unit Testing, part of Agile Development l Create a single class that matches the definition  Can add whatever other methods you like l Graded for correctness  Efficiency matters only in a binary way  Good design will be useful to you

CompSci 100e2.7 What can you put into an ArrayList? Any Object Scanner in = …; ArrayList list = new ArrayList (); while (in.hasNext()) list.add(in.next()); l Use a wrapper class (see java.lang.*)  int, double, char, boolean, …  Integer, Double, Character, Boolean, Can have your cake and eat it too ArrayList list = new ArrayList (); for (int k = 0; k < 10; k++) list.add(k*k); for (Integer jj : list) System.out.println(jj); l All made practical by Version 5 of Java

CompSci 100e2.8 Sets l Set is an unordered list of items  Items are unique! Only one copy of each item in set! l We will use two different implementations of sets TreeSet  A TreeSet is backed up by a tree structure (future topic)  Keeps items sorted (+)  Slower than HashSets ?? (-) HashSet  A HashSet is backed up by a hashing scheme (future topic)  Items not sorted – should seem to be in random order (-)  Faster than TreeSets ?? (+)