CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 645-4739 1.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
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.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE116: Introduction to Computer Science 2 Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Mixing types in expressions Operators such as +, -, * and / are overloaded: the same name has many different values + overloaded as String concatenation.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE 115 Week 11 March , Announcements March 26 – Exam 7 March 26 – Exam 7 March 28 – Resign Deadline March 28 – Resign Deadline Lab 7 turned.
Arrays An array is a collection of variables, all of the same type. An array is created with the new operator. The size of an array must be specified at.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall 1.
Arrays, Conditionals & Loops in Java. Arrays in Java Arrays in Java, are a way to store collections of items into a single unit. The array has some number.
CSE 143 Lecture 7 Sets and Maps reading: ; 13.2 slides created by Marty Stepp
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
COMP 1001: Introduction to Computers for Arts and Social Sciences Programming in Scratch Monday, May 16, 2011.
Grouping objects Collections and iterators. Main concepts to be covered Collections Loops Iterators.
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1.
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 1.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
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
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Computer Science 209 Software Development Java Collections.
The Java Collections Framework By the end of this lecture you should be able to: use the ArrayList class to store a list of objects; use the HashSet class.
1 Iterators "First things first, but not necessarily in that order " -Dr. Who CS Computer Science II.
Thanks, Andrew. Reminders: –wear the wireless mike –combination is 1-31 –speak slowly, pause for questions –I’d rather you get through less material than.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Recitation 5 Enums and The Java Collections classes/interfaces 1.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Collections Dwight Deugo Nesa Matic
Iterators. Iterator  An iterator is any object that allows one to step through each element in a list (or, more generally, some collection).
Sets Set is an unordered list of items
Fundamentals of Java: AP Computer Science Essentials, 4th Edition
Agenda Warmup Finish 2.4 Assignments
Collections Framework
CISC181 Introduction to Computer Science Dr
Comparing Python and Java
Presentation transcript:

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall

Agenda Announcements – Cell phones / laptops off & away / Name signs out Last time –Finch classroom exercise Today –Collection framework Collection interface ArrayList class HashSet class foreach loop – control structure

Collections A collection object can store arbitrarily many references to objects. We will first learn to become users/clients of collections. Next semester we will learn to become builders of collections.

java.util.Collection interface All collection classes in Java are subtypes of the java.util.Collection interface. ‘ ’ is new syntax –E is a type variable, and denote the element type of the collection: Collection denotes a collection of String objects Collection denotes a collection of ActionListener objects Among the methods specified in the interface: –boolean add(E item) --- tries to add item to the collection; if this is successful, true is returned, false otherwise –boolean remove(Object item) --- tries to remove item from the collection; if this is successful, true is returned, false otherwise –boolean contains(Object item) --- returns true if item is in the collection, false otherwise –int size() --- return the number of items currently in the collection

Two specific collections ArrayList –permits duplicates –allows client to control order of elements HashSet –does not permit duplicates –does not allow client to control order of elements

Collections: usage example To declare a variable of type HashSet of String: HashSet names; To create a HashSet of String object, and assign its reference to the variable declared above: names = new HashSet ();

Collections: usage example (continued) To add a String to the HashSet: names.add(“Fred”); To remove a String from the HashSet: names.remove(“Fred”);

foreach loop A foreach loop is a control structure that repeats a block of code, once for each element in a collection. Syntax for ( : ) ; Example: Collection names = new ArrayList (); names.add(“Fred”); names.add(“Wilma”); for (String s : names) { System.out.println(“Name is “+s); } Prints: Name is Fred Name is Wilma