Java Collections

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + jboutelle Jonathan Boutelle 3 years ago
    Parag,
    Nice slideshow! One quick piece of feedback: presentation seems to be classified as Romanian, even though it’s in English...
Post a comment
Embed Video
Edit your comment Cancel

4 Favorites

Java Collections - Presentation Transcript

  1. Java Collections
      • Parag Shah
      • Adaptive Software Solutions
      • http://www.adaptivelearningonline.net
      • http://www.adaptivesoftware.biz
  2. Agenda
    • Collection classes in Java
      • New
      • Legacy
    • Iterating through collections
  3. Introduction
    • The need for holding objects
    • Collection support in Java
      • Array
      • Vector
      • Hashmap
      • List
      • Set
      • Map
  4. Array
    • Arrays are first class objects
    • Advantages of using Arrays
      • Efficient
      • Type of objects determined at compile time
      • Can store primitives directly
    • Disadvantages of using Arrays
      • The size is fixed
      • The type of objects it can store is fixed
  5. The Java Collections Library
    • Basic Collection Interfaces
      • Collection
        • List
        • Set
      • Map
  6. Basic Collection Classes
    • Basic Collection Classes
  7. Collection Classes (contd.)
    • Classes that work with Collections
  8. Collection Classes Overview
    • Collection: Stores a collection of objects, such that a rule is applied to the objects
      • List: Stores objects in a certain order
        • Implemented By
          • ArrayList
          • LinkedList
      • Set: Stores only unique objects
        • Implemented By
          • HashSet
          • TreeSet
    • Map: Stores key-value pairs
        • Implemented By
          • HashMap
          • TreeMap
          • WeakHashMap
  9. Collection Interface
    • java.util.Collection
      • Root Interface for the Collection hierarchy in Java
      • Holds a group of objects which adhere to some rule
      • Classes implementing this Interface are suggested to have atleast 2 constructors:
        • A no-arg constructor
        • A constructor which takes a collection of objects
  10. List
    • java.util.List
      • A List is an ordered collection of objects
        • Implemented by ArrayList, and LinkedList
      • Users have control on where in the List, new elements should be added
      • Lists can contain duplicates as determined by the equals() method
      • Use caution while adding a List element to a List
        • equals(), and hashCode() may not work properly
  11. ArrayList
    • See [SimpleArrayList.java]
    • java.util.ArrayList
      • Resizable array implementation of the List Interface
      • Adding elements require O(n) time
      • Other operations are performed linear time
      • The capacity of ArrayLists can be increased before adding a large number of elements
      • ArrayList is NOT synchronized
      • Inserting elements in the list is inefficient
  12. LinkedList
    • See [SimpleLinkedList.java]
    • java.util.LinkedList
      • Doubly Linked List implementation of the List Interface
      • Provides special methods to get, remove, and insert elements at the beginning and the end of the list
        • Enables the usage of a LinkedList as:
          • Queues
          • Stacks
          • Deque
      • Inefficient for random access
      • Very efficient for sequential access and insertions in the middle of the list
      • LinkedList's are not synchronized
  13. Set
    • java.util.Set
      • A Set is a Collection that does not contain any duplicate elements
      • Elements that are put in a Set must override the equals() method to establish uniqueness
      • A Set cannot contain itself as an element
      • Caution must be exercised when adding a mutable element to a set
  14. HashSet
    • See [SimpleHashSet.java]
    • java.util.HashSet
      • A Set backed by a HashMap
      • Can contain nulls
      • Basic operations take constant time
      • Iteration order may not always be the same
      • Used for Sets where lookup time has to be optimized
      • User defined classes must override the hashCode() method
      • Operations not synchronized
  15. TreeSet
    • See [SimpleTreeSet.java]
    • java.util.TreeSet
      • A Set backed by a TreeMap
      • The sorted Set is gauranteed to be in ascending order, sorted by the natural order of the elements or by the comparator provided
      • User defined classes must implement the Comparable Interface
      • A TreeSet is not synchronized
  16. Map
    • java.util.Map
      • It is an associative array
      • Used to lookup objects based on keys
      • Implemented by the HashMap and TreeMap classes
  17. HashMap
    • See [SimpleHashMap.java]
    • java.util.HashMap
      • Implementation is based on a Hashtable
      • Ideal for fast lookups
      • Provides constant time performance for inserting and locating pairs
      • Allows null for keys and values
      • Methods are not synchronized
  18. TreeMap
    • See [SimpleTreeMap.java]
    • java.util.TreeMap
      • Implemented based on Red-Black trees
      • The keys appear sorted
      • Basic operations take log(n) time
      • The ordering maintained by HashMap must be consistent with equals()
      • Methods are not synchronized
  19. Iterators
    • Iterators provide the ability to traverse through a sequence of elements without knowing the underlying data structure of the sequence
    • Iterator support in Java
      • Interface Iterator
        • Allows unidirectional traversal and removal of elements from the underlying collection
      • Interface ListIterator
        • Allows bi-directional traversal as well as addition, removal, & substitution of elements in the underlying collection
  20. Using Iterators
    • Always use iterators and not for loops while iterating through collections
    • Use Iterator to iterate and remove elements from a collection
    • ListIterator provides more features
      • Allows insertion & replacement of elements
      • Allows bi-directional navigation
    • See [ListIterationExample.java]
    • See [MapIteration.java]
  21. Summary
    • Revise various collection interfaces and their implementations
    • Discuss pros and cons of choosing the collection type
    • Discuss legacy collection types
  22. Where to Get More Information
    • Bruce Eckel's – Thinking in Java
    • Java tutorial

+ paragparag, 3 years ago

custom

8776 views, 4 favs, 8 embeds more stats

More info about this document

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Go to text version

  • Total Views 8776
    • 8615 on SlideShare
    • 161 from embeds
  • Comments 1
  • Favorites 4
  • Downloads 94
Most viewed embeds
  • 64 views on http://www.indijava.in
  • 59 views on http://indijava.in
  • 29 views on http://hpfloresj.blogspot.com
  • 4 views on http://www.slideshow.com
  • 2 views on http://www.techiegyan.com

more

All embeds
  • 64 views on http://www.indijava.in
  • 59 views on http://indijava.in
  • 29 views on http://hpfloresj.blogspot.com
  • 4 views on http://www.slideshow.com
  • 2 views on http://www.techiegyan.com
  • 1 views on http://scitjava.blogspot.com
  • 1 views on http://slideshow.com
  • 1 views on http://www.dvd-photo.slideshow.com

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories