SlideShare a Scribd company logo
java.util and
                     CollectionFramework




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
• This presentation is for teaching purpose only.
    • This presentation may contain some material
      from books / api documentation / internet.
    • No intention of breaking any rights or what so
      ever.




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Date and Time Related Classes
    •   Date
    •   TimeZone
    •   Calendar
    •   GregorianCalendar

    • Epoch : 1st Jan 1970 0:0:0.0 GMT
         – 1st January 1970 5:30:0.0 IST


Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Simple Program




                                            ????????? toString()
Available at : http://www.asbspace.in/ppt                   Prof. Ashish Bhatia
Constructor




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Comparing Date




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Calendar
    •   Abstract Class
    •   No public constructor
    •   day, month, year, hour, minutes , seconds, era
    •   Many int constants
    •   Many methods




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Some Methods




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
TimeZone
    • Class
    • Maintains offset value
    • ID for instances

    • public static TimeZone getDefault()
    • public static void setDefault(TimeZone zone)



Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
•   public String getId()
    •   public String getDisplayName()
    •   public int getOffset(long date)
    •   public int getRawOffset
    •   public void setRawOffset(int offmilliseconds)
    •   public static TimeZone getTimeZone(String ID)



Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
GregorianCalendar
    •   Concrete class of Calendar
    •   Two fields AD and BC for era
    •   7 constructors
    •   GreogrianCalendar gc = new
        GregorianCalendar();
         – Current date and time in default locale and time
           zone



Available at : http://www.asbspace.in/ppt         Prof. Ashish Bhatia
GregorianCalendar
    • Ff




   Year = Number of year elapsed from 1900
   Month = 0 indicating Jan

Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
GregorianCalendar
    fd




    • boolean isLeapYear(int year)
         – Test for leap year



Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
DateFormat




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Array Class


    • Contains various methods for manipulating
      arrays - mostly static methods
    • Contains a static factory that allows arrays to
      be viewed as lists.
    • fill, equals, sort, binarysearch, toString


Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
fill method
    • public static void fill(datatype[] array, datatype
      value)
    • public static void fill(datatype[] array, int
      fromindex , int toindex, datatype value)

    • datatype = Primitive Datatype + Object



Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Program




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Output




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
fill()




Available at : http://www.asbspace.in/ppt            Prof. Ashish Bhatia
fill()




Available at : http://www.asbspace.in/ppt            Prof. Ashish Bhatia
equals()
    • Return Boolean
    • Take two arguments
    • public static boolean equals( datatype [] a,
      datatype[] b)

    • Compare each element and size of array



Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
equals()




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
sort()
    • Sort the array
    • Ascending Order




Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
sort()




Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
binarySearch()
    • Uses binary search method to find the index
      of element
    • Prerequisites : Sorted Array




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
binarySearch()




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Collection Framework
    • Standardizing and having interoperability
      between various data structures
    • Introduced in Java 1.2
    • Relies on Standard interfaces




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Collection Framework
    • Eight generics interfaces type
         – Determined the common methods for all
           collection class
    • Operations
         – Basic Operations
         – Array Operations
         – Bulk Operations



Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Basic Operations




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Basic Operations




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Array Operations




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Bulk Operation




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Iterator
    • Lets you cycle through collection




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
Example




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Set Interface
    • Defines a set
    • Collection of unique element [ no duplication]
    • Extends the Collection
         – All the methods
    • HashSet and TreeSet are concrete classes
    • AbstractSet : base abstract class



Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
List Interface
    •   Extends Collection
    •   Insertion, updating, all are index based
    •   Index starts from 0
    •   It can store duplicates value
    •   It adds its own methods




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
Methods




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Methods




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Methods




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
List Iterator
    • public interface ListIterator<E> extends
      Iterator<E>
    • A ListIterator has no current element;
      its cursor position always lies between the
      element that would be returned by a call
      toprevious() and the element that would be
      returned by a call to next().
    • An iterator for a list of length n has
      n+1 possible cursor positions,
Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
List Iterator


    •




Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
List Iterator
   • In general, to use an iterator to cycle through
     thecontents of a collection, follow these steps:
   1.Obtain an iterator to the start of the collection
     by calling the collection’s iterator( ) method.
   2.Set up a loop that makes a call to hasNext( ).
     Have the loop iterate as long as hasNext( )
     returns true.
   3.Within the loop, obtain each element by
     calling next( ).
Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class
    • Dynamic Array
         – The size of a Vector can grow or shrink as needed
           to accommodate adding and removing items after
           the Vector has been created


    • Synchronized
    • Each vector tries to optimize storage
      management by maintaining a capacity and
      a capacityIncrement
Available at : http://www.asbspace.in/ppt        Prof. Ashish Bhatia
Vector Class
    • Modified from Java 1.2 [ IS IT SAME AS JAVA
      2]
    • To implement List and become part of
      Collection Framework




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class Constructors

                                            Initial Size 10




    • The increment specifies the number of
      elements to allocate each time that a vector is
      resized upward.
Available at : http://www.asbspace.in/ppt         Prof. Ashish Bhatia
Vector Class
    • Starts with initial capacity
    • Allocates more space for new objects once the
      capacity is reached
    • It allocates more space that required so
      allocation is done minimal time
    • Double size if nothing is specified
    • What if incr size = 0 [ Default Value]


Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Vector Class




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Now Lets add elements




    • addElement(Object o)

    • Size = ? Capacity = ?

Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
• Size = 4                              Capacity = 5
         – WHY



    •   Size = ?         Capacity = ?
    •   5,5
    •   5,8
    •   Any Other Option
Available at : http://www.asbspace.in/ppt                  Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Solution : Generics

    • <Object>
         – Specifies the data type


    • Vector<String> v = new Vector<String> ();
    • Vector<Rectangle> v = new
      Vector<Rectangle> ();


Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Printing Vector




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
One Example 




Available at : http://www.asbspace.in/ppt   Prof. Ashish Bhatia
Lets Create Vector




    • Size = ?? Capacity = ??
    • DEFAULT = 10

Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia
Will This Work !!!




Available at : http://www.asbspace.in/ppt      Prof. Ashish Bhatia
How to Print area ?




Available at : http://www.asbspace.in/ppt    Prof. Ashish Bhatia
Stack




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
ArrayList




Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
ArrayList
    • Resizable-array implementation of
      the List interface.
    • Implements all optional list operations, and
      permits all elements, including null.
    • This class is roughly equivalent to Vector,
      except that it is unsynchronized.



Available at : http://www.asbspace.in/ppt       Prof. Ashish Bhatia
Map Interface
    • Continued to Next Presentation




Available at : http://www.asbspace.in/ppt     Prof. Ashish Bhatia

More Related Content

Similar to Understanding Date Handling and Collection Framework (20)

PDF
Data types and operators and statements
asbasb82
 
PDF
Week 1 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
PDF
Java script
AshishSingh Bhatia
 
PDF
(eBook PDF) Data Structures and Other Objects Using Java 4th Edition
adweguggu
 
PDF
Data Structures
Prof. Dr. K. Adisesha
 
PDF
Effective stl notes
Uttam Gandhi
 
PPTX
datastructure-201021140600.pptx
ZISAN5
 
PPTX
Java Hands-On Workshop
Arpit Poladia
 
PPTX
QSpiders - Major difference
Qspiders - Software Testing Training Institute
 
PPT
Collections and generic class
ifis
 
PDF
1-5 ADS Notes.pdf
RameshBabuKellamapal
 
KEY
Objects & OO Thinking for Java
Jeff Sonstein
 
PDF
Java%20 collections%20framework
Ilakkian
 
PPTX
Collections Training
Ramindu Deshapriya
 
PPTX
Pptchdtdtfygugyxthgihhihigugufydtdfzrzrzrtdyfyfy
dnthulk
 
PPTX
Javasession7
Rajeev Kumar
 
PDF
Java Course 4: Exceptions & Collections
Anton Keks
 
PDF
Collections
Linh Lê
 
PDF
Java Collections Framework
guestd8c458
 
ODP
Java Collections
parag
 
Data types and operators and statements
asbasb82
 
Week 1 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
Java script
AshishSingh Bhatia
 
(eBook PDF) Data Structures and Other Objects Using Java 4th Edition
adweguggu
 
Data Structures
Prof. Dr. K. Adisesha
 
Effective stl notes
Uttam Gandhi
 
datastructure-201021140600.pptx
ZISAN5
 
Java Hands-On Workshop
Arpit Poladia
 
Collections and generic class
ifis
 
1-5 ADS Notes.pdf
RameshBabuKellamapal
 
Objects & OO Thinking for Java
Jeff Sonstein
 
Java%20 collections%20framework
Ilakkian
 
Collections Training
Ramindu Deshapriya
 
Pptchdtdtfygugyxthgihhihigugufydtdfzrzrzrtdyfyfy
dnthulk
 
Javasession7
Rajeev Kumar
 
Java Course 4: Exceptions & Collections
Anton Keks
 
Collections
Linh Lê
 
Java Collections Framework
guestd8c458
 
Java Collections
parag
 

More from ashishspace (6)

PDF
I/O In Java Part 2
ashishspace
 
PDF
I/O in java Part 1
ashishspace
 
PDF
Remote Method Invocation
ashishspace
 
PDF
Nested and Enum in Java
ashishspace
 
PDF
HTTP Basic and Servlet Basic
ashishspace
 
PDF
Java packages and access specifiers
ashishspace
 
I/O In Java Part 2
ashishspace
 
I/O in java Part 1
ashishspace
 
Remote Method Invocation
ashishspace
 
Nested and Enum in Java
ashishspace
 
HTTP Basic and Servlet Basic
ashishspace
 
Java packages and access specifiers
ashishspace
 
Ad

Recently uploaded (20)

PPTX
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
PDF
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
PDF
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PDF
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PDF
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PPTX
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
PPTX
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
 
PPTX
How to use _name_search() method in Odoo 18
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
ESP 10 Edukasyon sa Pagpapakatao PowerPoint Lessons Quarter 1.pptx
Sir J.
 
DLL english grade five goof for one week
FlordelynGonzales1
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Free eBook ~100 Common English Proverbs (ebook) pdf.pdf
OH TEIK BIN
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Nanotechnology and Functional Foods Effective Delivery of Bioactive Ingredien...
rmswlwcxai8321
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
Comparing Translational and Rotational Motion.pptx
AngeliqueTolentinoDe
 
A Case of Identity A Sociological Approach Fix.pptx
Ismail868386
 
Photo chemistry Power Point Presentation
mprpgcwa2024
 
How to use _name_search() method in Odoo 18
Celine George
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
Ad

Understanding Date Handling and Collection Framework

  • 1. java.util and CollectionFramework Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 2. • This presentation is for teaching purpose only. • This presentation may contain some material from books / api documentation / internet. • No intention of breaking any rights or what so ever. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 3. Date and Time Related Classes • Date • TimeZone • Calendar • GregorianCalendar • Epoch : 1st Jan 1970 0:0:0.0 GMT – 1st January 1970 5:30:0.0 IST Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 4. Simple Program ????????? toString() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 5. Constructor Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 6. Comparing Date Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 7. Calendar • Abstract Class • No public constructor • day, month, year, hour, minutes , seconds, era • Many int constants • Many methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 8. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 9. Some Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 10. TimeZone • Class • Maintains offset value • ID for instances • public static TimeZone getDefault() • public static void setDefault(TimeZone zone) Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 11. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 12. public String getId() • public String getDisplayName() • public int getOffset(long date) • public int getRawOffset • public void setRawOffset(int offmilliseconds) • public static TimeZone getTimeZone(String ID) Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 13. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 14. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 15. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 16. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 17. GregorianCalendar • Concrete class of Calendar • Two fields AD and BC for era • 7 constructors • GreogrianCalendar gc = new GregorianCalendar(); – Current date and time in default locale and time zone Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 18. GregorianCalendar • Ff Year = Number of year elapsed from 1900 Month = 0 indicating Jan Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 19. GregorianCalendar fd • boolean isLeapYear(int year) – Test for leap year Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 20. DateFormat Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 21. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 22. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 23. Array Class • Contains various methods for manipulating arrays - mostly static methods • Contains a static factory that allows arrays to be viewed as lists. • fill, equals, sort, binarysearch, toString Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 24. fill method • public static void fill(datatype[] array, datatype value) • public static void fill(datatype[] array, int fromindex , int toindex, datatype value) • datatype = Primitive Datatype + Object Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 25. Program Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 26. Output Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 27. fill() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 28. fill() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 29. equals() • Return Boolean • Take two arguments • public static boolean equals( datatype [] a, datatype[] b) • Compare each element and size of array Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 30. equals() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 31. sort() • Sort the array • Ascending Order Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 32. sort() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 33. binarySearch() • Uses binary search method to find the index of element • Prerequisites : Sorted Array Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 34. binarySearch() Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 35. Collection Framework • Standardizing and having interoperability between various data structures • Introduced in Java 1.2 • Relies on Standard interfaces Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 36. Collection Framework • Eight generics interfaces type – Determined the common methods for all collection class • Operations – Basic Operations – Array Operations – Bulk Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 37. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 38. Basic Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 39. Basic Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 40. Array Operations Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 41. Bulk Operation Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 42. Iterator • Lets you cycle through collection Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 43. Example Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 44. Set Interface • Defines a set • Collection of unique element [ no duplication] • Extends the Collection – All the methods • HashSet and TreeSet are concrete classes • AbstractSet : base abstract class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 45. List Interface • Extends Collection • Insertion, updating, all are index based • Index starts from 0 • It can store duplicates value • It adds its own methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 46. Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 47. Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 48. Methods Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 49. List Iterator • public interface ListIterator<E> extends Iterator<E> • A ListIterator has no current element; its cursor position always lies between the element that would be returned by a call toprevious() and the element that would be returned by a call to next(). • An iterator for a list of length n has n+1 possible cursor positions, Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 50. List Iterator • Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 51. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 52. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 53. List Iterator • In general, to use an iterator to cycle through thecontents of a collection, follow these steps: 1.Obtain an iterator to the start of the collection by calling the collection’s iterator( ) method. 2.Set up a loop that makes a call to hasNext( ). Have the loop iterate as long as hasNext( ) returns true. 3.Within the loop, obtain each element by calling next( ). Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 54. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 55. Vector Class • Dynamic Array – The size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created • Synchronized • Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 56. Vector Class • Modified from Java 1.2 [ IS IT SAME AS JAVA 2] • To implement List and become part of Collection Framework Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 57. Vector Class Constructors Initial Size 10 • The increment specifies the number of elements to allocate each time that a vector is resized upward. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 58. Vector Class • Starts with initial capacity • Allocates more space for new objects once the capacity is reached • It allocates more space that required so allocation is done minimal time • Double size if nothing is specified • What if incr size = 0 [ Default Value] Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 59. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 60. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 61. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 62. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 63. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 64. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 65. Vector Class Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 66. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 67. Now Lets add elements • addElement(Object o) • Size = ? Capacity = ? Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 68. • Size = 4 Capacity = 5 – WHY • Size = ? Capacity = ? • 5,5 • 5,8 • Any Other Option Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 69. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 70. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 71. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 72. Solution : Generics • <Object> – Specifies the data type • Vector<String> v = new Vector<String> (); • Vector<Rectangle> v = new Vector<Rectangle> (); Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 73. Printing Vector Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 74. One Example  Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 75. Lets Create Vector • Size = ?? Capacity = ?? • DEFAULT = 10 Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 76. Will This Work !!! Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 77. How to Print area ? Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 78. Stack Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 79. ArrayList Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 80. ArrayList • Resizable-array implementation of the List interface. • Implements all optional list operations, and permits all elements, including null. • This class is roughly equivalent to Vector, except that it is unsynchronized. Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia
  • 81. Map Interface • Continued to Next Presentation Available at : http://www.asbspace.in/ppt Prof. Ashish Bhatia