Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739

Similar presentations


Presentation on theme: "CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739"— Presentation transcript:

1 CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739 alphonce@buffalo.edu

2 Announcements Exam 3 on Wednesday 11/10 –covers material from last exam up to and including Friday 11/05 Review on Monday 11/08

3 Agenda Collections Inheritance – our last relationship!

4 Collections We have seen that a variable can hold one object reference at a time. How do we effectively deal with multiple references? –arbitrarily many –what does addActionListener do?

5 Collections interface: java.util.Collection (some) classes implementing interface: –java.util.HashSet –java.util.ArrayList E is the type of element contained in the collection – replace by an actual type

6 Use of a collection HashSet names = new HashSet (); names.add(“Amy”);names.remove(“Bob”); names.add(“Bob”); names.add(“Cindy”); names.add(“Dave”); names.add(“Emma”); …

7 for-each loop for (String name : names) { System.out.println(name); } This would print out: Amy Cindy Dave Emma

8 Code demo Consider types from last time: public interface Noisy { public void sound(); } public class Cat implements Noisy {...} public class Dog implements Noisy {...} This is clearly a toy example. We used this to illustrate the use of a collection, the foreach loop, and String concatenation.

9 String concatenation ‘+’ is the String concatenation operator If s1 and s2 are references to String objects, then s1+s2 is an expression whose value is a reference to a new String object, consisting of all the characters of s1, followed by all the characters of s2.


Download ppt "CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:50 645-4739"

Similar presentations


Ads by Google