COLLECTIONS Byju Veedu s/Collection.html.

Slides:



Advertisements
Similar presentations
11 Copyright © 2005, Oracle. All rights reserved. Using Arrays and Collections.
Advertisements

Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
JAVA Programming (Session 7) When you are willing to make sacrifices for a great cause, you will never be alone. Instructor:
Lecture 3 Introduction to Collections Advanced Java Programming 1 dr inż. Wojciech Bieniecki
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
Collections. What is the Collections framework?  Collections framework provides two things: –implementations of common high-level data structures: e.g.
Collections CS3250. Sources  Slides by Professor Chuck Allison  Core Java, by Cay S. Horstmann and Gary Cornell  The Java Tutorial 
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L16 (Chapter 22) Java Collections.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
Introduction to Java Collections
The Java Collections Package C. DeJong Fall 2001.
Chapter 19 Java Data Structures
Java's Collection Framework
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.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
CollectionsS CompSci 230 Software Construction.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
Java Programming: Advanced Topics 1 Collections and Wealth of Utilities.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
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.
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.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
Big Java Chapter 16.
111 © 2002, Cisco Systems, Inc. All rights reserved.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Chapter 18 Java Collections Framework
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
Data structures Abstract data types Java classes for Data structures and ADTs.
Collection 105 Yola. To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps.
The Java Collections Framework Based on
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
Java 2 Collections Bartosz Walter Software Engineering II.
1 Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain:
1 Interfaces in Java’s Collection Framework Rick Mercer.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
13 Collections Framework. 2 Contents What is Collection? Collections Framework Collections Hierarchy Collections Implementations Set List Map.
CS Ananda Gunawardena.  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Thomas Kuehne.
Nov 22, 2010IAT 2651 Java Collections. Nov 22, 2010IAT 2652 Data Structures  With a collection of data, we often want to do many things –Organize –Iterate.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
1 Copyright © 2011 Tata Consultancy Services Limited COLLECTIONS By TEAM 5 Rajendhiran Sivan Christi Yashwanth Bijay Smruthi Satyajit.
University of Limerick1 Collections The Collection Framework.
Collections Dwight Deugo Nesa Matic
Java Collection Classes Com379PT
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Introduction to Java Collection. Java Collections What are they? –A number of pre-packaged implementations of common ‘container’ classes, such as LinkedLists,
Collections ABCD ABCD Head Node Tail Node array doubly linked list Traditional Arrays and linked list: Below is memory representation of traditional.
Using the Java Collection Libraries COMP 103 # T2
Sixth Lecture ArrayList Abstract Class and Interface
Chapter 19 Java Data Structures
JAVA COLLECTIONS LIBRARY
Road Map CS Concepts Data Structures Java Language Java Collections
Road Map CS Concepts Data Structures Java Language Java Collections
Java语言程序设计 马 皓
14.1 The java.util Package.
Collections Not in our text.
Chapter10 Collections.
Programming Languages
Presentation transcript:

COLLECTIONS Byju Veedu s/Collection.html

Introduction A collection is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data. Typically, they represent data items that form a natural group, such as a poker hand (a collection of cards), a mail folder (a collection of letters), or a telephone directory (a mapping of names to phone numbers). Eg: List,Map,Set Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.

Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain the following: Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages, interfaces generally form a hierarchy. Implementations: These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures. Algorithms: These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface. In essence, algorithms are reusable functionality. Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.

Interfaces

Implementations

Collection Interface

Set import java.util.*; public class FindDups { public static void main(String[] args) { Set s = new HashSet (); for (String a : args){ if (!s.add(a)) { System.out.println("Duplicate detected: " + a); } System.out.println(s.size() + " distinct words: " + s); }

List import java.util.Arrays; import java.util.Collections; import java.util.List; public class NameList { public static void main(String[] args) { List list = Arrays.asList(args); list.add("Kumar");// adding a new object list.remove(0); //removing the 0th element //Shuffling Collections.shuffle(list); System.out.println(list); //Sorting Collections.sort(list); System.out.println(list); }

Queue import java.util.*; public class CountDownQueue { public static void main(String[] args) throws InterruptedException { int time = Integer.parseInt(args[0]); Queue queue = new LinkedList (); for (int i = time; i >= 0; i--) queue.add(i); while (!queue.isEmpty()) { System.out.println(queue.remove()); Thread.sleep(1000); }

Map import java.util.HashMap; import java.util.Map; public class FreqencyMap { public static void main(String[] args) { Map m = new HashMap (); // Initialize frequency table from command line for (String a : args) { Integer freq = m.get(a); m.put(a, (freq == null) ? 1 : freq + 1); } System.out.println(m.size() + " distinct words:"); System.out.println(m); }

Algorithms The polymorphic algorithms are pieces of reusable functionality provided by the Java platform. All of them come from the Collections class, and all take the form of static methods whose first argument is the collection on which the operation is to be performed. * Sorting * Shuffling * Routine Data Manipulation(reverse,fill,copy,addAll,swap) * Searching(binarySearch) * Composition(frequency,disjoint) * Finding Extreme Values(minimum and maximum)

Historical Collection Classes Arrays Vector Stack Enumeration Interface Dictionary Hashtable Properties

You should know When to use Array and ArrayList Use of equals and hashcode Use of linked list Sorting and comparing Synchronized collections Iterating collections

Benefits of Collection framework Reduces programming effort: By providing useful data structures and algorithms, the Collections Framework frees you to concentrate on the important parts of your program rather than on the low-level "plumbing" required to make it work. Increases program speed and quality: This Collections Framework provides high- performance, high-quality implementations of useful data structures and algorithms.. Because you're freed from the drudgery of writing your own data structures, you'll have more time to devote to improving programs' quality and performance. Allows interoperability among unrelated APIs: The collection interfaces are the vernacular by which APIs pass collections back and forth. If my network administration API furnishes a collection of node names and if your GUI toolkit expects a collection of column headings, our APIs will interoperate seamlessly, even though they were written independently. Reduces effort to learn and to use new APIs: Many APIs naturally take collections on input and furnish them as output. In the past, each such API had a small sub-API devoted to manipulating its collections. There was little consistency among these ad hoc collections sub-APIs, so you had to learn each one from scratch, and it was easy to make mistakes when using them. With the advent of standard collection interfaces, the problem went away. Reduces effort to design new APIs: This is the flip side of the previous advantage. Designers and implementers don't have to reinvent the wheel each time they create an API that relies on collections; instead, they can use standard collection interfaces. Fosters software reuse: New data structures that conform to the standard collection interfaces are by nature reusable. The same goes for new algorithms that operate on objects that implement these interfaces. Copyright © 1995, 2010 Oracle and/or its affiliates. All rights reserved.

Hands-on Use of 1. ArrayList and Vector 2. HashMap and Hashtable 3. HashSet 4. TreeSet and TreeMap 5. Queue Sorting a List Binary search on list Using Comparator Using iterator

References ons/index.html ons/index.html ctions/Collection.html ctions/Collection.html