For use of Cleveland State's IST410 Students only 1 Vectors and Collections.

Slides:



Advertisements
Similar presentations
Chapter 81 JavaBeans JavaServer Pages By Xue Bai.
Advertisements

OO Programming Objectives for today: Casting Objects Introduction to Vectors The instanceof keyword.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
5-May-15 ArrayLists. 2 ArrayList s and arrays A ArrayList is like an array of Object s Differences between arrays and ArrayList s: Arrays have special.
L2. Necessary Java Programming Techniques (Vector) Packages  Java.util import Java.util.*; Classes  Vector Interfaces  Enumeration Java API.
CS 106 Introduction to Computer Science I 04 / 27 / 2007 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
15-Jun-15 Lists in Java Part of the Collections Framework.
1 Java intro Part 3. 2 Arrays in Java Store fixed number of values of a given type Arrays are objects –have attributes –must be constructed Array declaration:
1 Dynamic Arrays  Why Dynamic Arrays?  A Dynamic Array Implementation  The Vector Class  Program Example  Array Versus Vector.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
25-Jun-15 Vectors. 2 Vectors and arrays A Vector is like an array of Object s Differences between arrays and Vector s: Arrays have special syntax; Vector.
Vectors. Vectors and arrays A Vector is like an array of Object s Differences between arrays and Vector s: –Arrays have special syntax; Vector s don’t.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
Static Class Members Wrapper Classes Autoboxing Unboxing.
12-Jul-15 Lists in Java Part of the Collections Framework.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
ARRAYLIST Collections of Data. ArrayLists Array lists can grow and shrink as needed ArrayList is a generic class (similar to C++ template) ArrayList has.
04/29/ Introduction to Vectors?... A vector is a dynamic array. - It can be expanded and shrunk as required - A Component of a vector can be accessed.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
GENERIC COLLECTIONS. Type-Wrapper Classes  Each primitive type has a corresponding type- wrapper class (in package java.lang).  These classes are called.
ArrayList, Multidimensional Arrays
Lists Ellen Walker CPSC 201 Data Structures Hiram College.
1 Java: AP Curriculum Focus and Java Subset Alyce Brady.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
CS 106 Introduction to Computer Science I 04 / 25 / 2008 Instructor: Michael Eckmann.
Chapter overview This chapter focuses on Array declaration and use Bounds checking and capacity Arrays storing object references Variable length parameter.
1 Generics Chapter 21 Liang, Introduction to Java Programming.
Javadoc A very short tutorial. What is it A program that automatically generates documentation of your Java classes in a standard format For each X.java.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Dynamic Data Structures and Generics Chapter 10. Outline Vectors Linked Data Structures Introduction to Generics.
1 Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain:
Arrays…JavaCPython have fixed lengthyes*yesno are initialized to default values yesno? track their own lengthyesnoyes trying to access “out of bounds”
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Chapter 3: Using Classes and Objects Coming up: Creating Objects.
List data type(ADT). Lists Elements : a 1,a 2,a 3,… a i-1,a i, a i+1,…a n Null List contains: 0 elements Types of Operations on list 1.Insertion 2.Deletion.
CS1020 Data Structures and Algorithms I Lecture Note #6 Vector and ArrayList.
Wrapper Classes Use wrapper objects in Collections when you can’t use primitive types Primitive TypeWrapper Class byteByte shortShort intInteger longLong.
Collections Dwight Deugo Nesa Matic
C19: Collection Classes (don’t forget to look at all the online code examples)
Object Oriented Programming in Java Habib Rostami Lecture 7.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 GEORGE KOUTSOGIANNAKIS Copyright: 2016 Illinois Institute of Technology/George Koutsogiannakis 1.
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
1 CS162: Introduction to Computer Science II Abstract Data Types.
Fundamental of Java Programming
Using the Java Collection Libraries COMP 103 # T2
The Class ArrayLinearList
COP 3503 FALL 2012 Shayan Javed Lecture 8
List Representation - Array
TCSS 143, Autumn 2004 Lecture Notes
Programming in Java Lecture 11: ArrayList
(Java Collections Framework) AbstractSequentialList
Java Arrays & Strings.
L2. Necessary Java Programming Techniques
Grouped Data Arrays, and Array Lists.
The Vector Class An object of class Vector is similar to an array in that it stores multiple values However, a vector only stores objects does not have.
L2. Necessary Java Programming Techniques
ArrayLists 22-Feb-19.
Collections Framework
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
ArrayLists.
ArrayLists 27-Apr-19.
ArrayList.
Presentation transcript:

For use of Cleveland State's IST410 Students only 1 Vectors and Collections

For use of Cleveland State's IST410 Students only 2 Wrapper Classes l I n many cases, we need to create collection of objects i.e dissimilar objects l A mechanism is needed so that we can include primitive data types in such collections l Wrapper classes provide that mechanism l For each primitive data type, there exists a wrapper class l Wrapper class objects are immutable

For use of Cleveland State's IST410 Students only 3 Wrapper Classes Primitive TypeWrapper Class booleanBoolean byteByte charCharacter doubleDouble floatFloat intInteger longLong shortShort l Wrapper classes provide methods through which one can convert one type to another

For use of Cleveland State's IST410 Students only 4 Vectors l Vectors are arrays of Objects l Vector is a class in java.util l JVM takes the responsibility of expanding Vectors dynamically as the existing capacity is used up l Inheritance hierarchy for Vector java.lang.Object java.util.AbstractCollection java.util.AbstractList java.util.Vector

For use of Cleveland State's IST410 Students only 5 Instance Variables of Vector l A Vector has 3 instance variables m protected int capacityIncrement - growth size m protected int elementCount - number of elements m protected Object [] elementData - buffer to store Objects l There are 4 constructors m Vector() -can hold 10 elements to start with m Vector(int initialCapacity) m Vector(int intialCapacity, int capacityIncrement) capacity is doubled when capacityIncrement is not specified m Vector(Collection c)

For use of Cleveland State's IST410 Students only 6 A few methods of Vector l void add(int index, Object e) - insert e at index l boolean add(Object o) - append l void addElement(Object o) - append l int capacity() - current capacity of vector l void clear() - remove all elements l boolean contains(Object e) - Test for Object e using equals l Object elementAt(int index) - return the obj at index l Object get(int index) - return Obj at index l int indexOf(Object e) - searches for first occurence l void insertElementAt(Object obj, int index)

For use of Cleveland State's IST410 Students only 7 A few methods of Vector l boolean remove(Object o) - remove first occurrence l void removeAllElements() - make the Vector empty l Object set(int index, Object e) - replace at index l int size() - returns the count of elements l Vector test example m TestVector.java l Use of a Vector to implement a stack m IntegerStack.java m StackTest.java

For use of Cleveland State's IST410 Students only 8 ArrayList l Java added a new class called ArrayList since jdk1.2 l This list can be used instead of Vectors l Our tests show that ArrayList is a faster collection class than Vectors l Each ArrayList has a capacity and this capacity is as large as the list size l The capacity grows automatically as elements are added

For use of Cleveland State's IST410 Students only 9 ArrayList l Three constructors m ArrayList() m ArrayList(Collection c) m ArrayList(int intialCapacity) l Methods to perform normal operations such as append to the list, remove from the list, check for empty list and so on l It also provides an interface to a listIterator object

For use of Cleveland State's IST410 Students only 10 ArrayList l Example of ArrayList and listIterator m ObjectList.java m SimulateQue.java

For use of Cleveland State's IST410 Students only 11 Javadoc: an aside l javadoc is a tool that comes with jdk and is a very handy tool to document your java programs l The usage of javadoc m javadoc [options] [packages|files] where Option Description -d output pathGenerated HTML files are stored in the directory -sourcepath directoryRoot directory of source file package tree -publicInclude only public members i output (default) -privateInclude both public and private members Example: javadoc -d. -public DynamicArray.java

For use of Cleveland State's IST410 Students only 12 Javadoc: an aside l As you know, java incorporates documentation tags within javadoc comments l The general organization of javadoc comments m javadoc comments should immediately precede the declaration m Start the comment with a Summary sentence and then follow with other sentences to document details of the declaration, its usage etc. m Include javadoc comment tags as necessary m Comments can include HTML tags such as,, etc.

For use of Cleveland State's IST410 Students only 13 Javadoc: an aside l Some common javadoc tags