Collection 105 Yola. To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps.

Slides:



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

Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 21 Generics.
15-Jun-15 Lists in Java Part of the Collections Framework.
12-Jul-15 Lists in Java Part of the Collections Framework.
Chapter 19 Java Data Structures
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
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.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Lecture 4 The Java Collections Framework. Java Container Classes.
Copyright © Texas Education Agency, Advanced Computer Programming Data Structures: Collections.
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.
DataStructures1 Barb Ericson Georgia Tech July 2008.
ADSA: Collections/ Advanced Data Structures and Algorithms Objective –give an overview of Collection classes, and create/use a Bag class Semester.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
111 © 2002, Cisco Systems, Inc. All rights reserved.
The basics of the array data structure. Storing information Computer programs (and humans) cannot operate without information. Example: The array data.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
COLLECTIONS Byju Veedu s/Collection.html.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
Collections. The Plan ● Why use collections? ● What collections are available? ● How are the collections different? ● Examples ● Practice.
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Collections –data structures and Algorithms L. Grewe.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Chapter 8 Collection.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
Java.util.Vector Brian Toone 10/3/07 Updated 10/10/07.
Arrays, ArrayLists, and Collections. Rationale Suppose we have a program to compute the average of three numbers. We could write a simple little method.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
Georgia Institute of Technology Workshop for CS-AP Teachers Data Structures Barb Ericson June 2006.
Java 2 Collections Bartosz Walter Software Engineering II.
SETS AND MAPS Collections of Data. Advanced Data Structures Often referred to as the Java Collections Framework…. Set and map data types Hash tables Binary.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
13 Collections Framework. 2 Contents What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Recitation 5 Enums and The Java Collections classes/interfaces 1.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
CS Fall 2012, Lab 04 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /29/2016 Changes of Office Hours  Monday.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Java Collection Classes Com379PT
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 19 Java Data Structures
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Data Structures and Database Applications Abstract Data Types
CSE 143 Lecture 9 References and Linked Nodes reading: 3.3; 16.1
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Java语言程序设计 马 皓
14.1 The java.util Package.
Welcome to CSE 143! Go to pollev.com/cse143.
Array Lists CSE 1310 – Introduction to Computers and Programming
Collections Framework
1.4 ทบทวน JAVA OO Programming Concepts Declaring and Creating Objects
Consider the following code:
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Collection 105 Yola

To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps

Collection Queue - a collection of values awaiting a processing. FIFO List – an ordered collection Set – a collection without duplicates Map – use associative keys. Search by its value but not the index Two interfaces for the dynamic data structures

How to use ArrayList import java.util.ArrayList; import java.util.Scanner; public class ArrLstExt { public static void main(String[] args) { ArrayList city = new ArrayList (); String name=""; Scanner a = new Scanner(System.in); while(!name.equals("stop")){ System.out.println("Input a name:"); name = a.next(); city.add(name); } city.set(1, "first city"); // to modify an element; }

Assignment 1 1.Implement search on the array list 2.Implement sort (find a method) 3.Implement shuffle (find a method) 4.Find min and max (find a method) 5.Swap two elements of an ArrayList

How to use queue import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class QueueEx { public static void main(String[] args) { Queue city = new LinkedList(); String name=""; Scanner a = new Scanner(System.in); while(!name.equals("stop")){ System.out.println("Input a name:"); name = a.next(); city.add(name); } System.out.println(city.poll()); // to remove the first item System.out.println(city.poll()); // to see without removing }

Assignment Input several values to queue Input several values to another List Synchronize queue to the List (leave only elements that present in the List)

How to use Set import java.util.HashSet; import java.util.Set; public class SetEx { public static void main(String[] args) { Set city = new HashSet(); Set city1 = new HashSet(); city.add("a"); city.add("b"); city.add("c"); city1.add("c"); city.add("d"); System.out.println(city.contains("a")); System.out.println(city.hashCode()==city1.hashCode()); city.retainAll(city1);// intersection of sets }}

How to use Map? This is HOME ASSIGNMENT!