34
Java Collections Framework A presentation by Eric Fabricant

Java Collections Framework

  • Upload
    jody

  • View
    155

  • Download
    8

Embed Size (px)

DESCRIPTION

Java Collections Framework. A presentation by Eric Fabricant. What is it?. “The Collections Framework provides a well-designed set of interfaces and classes for storing and manipulating groups of data as a single unit, a collection.” -java.sun.com. So what?. - PowerPoint PPT Presentation

Citation preview

Page 1: Java  Collections Framework

Java Collections Framework

A presentation by Eric Fabricant

Page 2: Java  Collections Framework

What is it?

“The Collections Framework provides a well-designed set of interfaces and classes for storing and manipulating groups of data as a single unit, a collection.” -java.sun.com

Page 3: Java  Collections Framework

So what?Well, The framework provides a convenient API to many of the abstract data types familiar to computer science: maps, sets, lists, trees, arrays, hashtables and other collections.

Page 4: Java  Collections Framework

What does it look like?

Page 5: Java  Collections Framework

The Basics

simple, but not

really. • Set

• List

• Map

Page 6: Java  Collections Framework

What makes a Set a Set?

No duplicate elements are allowed, such that e1.equals(e2) is true.

Page 7: Java  Collections Framework

More on Sets• The Set Interface extends the Collection Interface.

• AbstractSet implements Set and extends AbstractCollection

•AbstractSet is a convenience class that contains basic concrete implementation.

Page 8: Java  Collections Framework

Types of Sets

• HashSet

• LinkedHashSet

• TreeSet

Page 9: Java  Collections Framework

HashSet• Implements the Set interface, backed by a hash table (actually a HashMap instance). •Makes no guarantees as to the iteration order of the set.• It does not guarantee that the order will remain constant over time. •Permits the null element.

Page 10: Java  Collections Framework

LinkedHashSet

• Extends HashSet.• Implements doubly-linked list.• Can retrieve elements based on insertion-order. • Less efficient than HashSet.

Page 11: Java  Collections Framework

TreeSet• Extends AbstractSet, implements SortedSet

• Elements can be kept in acscending order according to compareTo() or compare()

• All elements must be comparable.

Page 12: Java  Collections Framework

Any questions?

Page 13: Java  Collections Framework

What makes a List a List?

Duplicate elements are allowed and position-oriented operations are permitted.

Page 14: Java  Collections Framework

More on Lists• The List Interface extends the Collection Interface.

• AbstractList implements List and extends AbstractCollection

•AbstractList is a convenience class that contains basic concrete implementation.

Page 15: Java  Collections Framework

Types of Lists• ArrayList• LinkedList• Vector• Stack

Page 16: Java  Collections Framework

ArrayList• Extends AbstractList

• Auto-resizeable.

• Based on a simple array.

• Permits the null element.

Page 17: Java  Collections Framework

LinkedList• Extends AbstractSequentialList, which extends AbstractList

•Similar to ArrayList

• Different implementation based on nodes that contain data and links to other nodes.

Page 18: Java  Collections Framework

Nodes In Action

Page 19: Java  Collections Framework

Vector• Similar to ArrayList

• Contains synchronized methods.

Page 20: Java  Collections Framework

Stack• Extends Vector

• “Last in, First Out” behavior

• Contains methods to allow typical Stack behaviors. (ie: push(), pop(), etc. )

Page 21: Java  Collections Framework

Any questions?

Page 22: Java  Collections Framework

What makes a Map a Map?

The collection is kept in key/value pairs. Any object can be a key or value. No duplicate keys allowed.

Page 23: Java  Collections Framework

More on Maps• The Map Interface does not extend the Collection Interface.

• AbstractMap implements Map and does not extend AbstractCollection

•AbstractMap is a convenience class that contains basic concrete implementation.

Page 24: Java  Collections Framework

Types of Maps• TreeMap

• HashMap

• LinkedHashMap

Page 25: Java  Collections Framework

TreeMap• Implements SortedMap, extends AbtractMap

• Keys can be kept in acscending order according to compareTo() or compare()

Page 26: Java  Collections Framework

HashMap• Implements SortedMap, extends AbstractMap

• Permits the null element.

• Makes no guarantees as to the iteration order of the set.

Page 27: Java  Collections Framework

More HashMap

•It does not guarantee that the order will remain constant over time.

• Can retrieve elements based on insertion-order or access order.

Page 28: Java  Collections Framework

LinkedHashMap

• Extends Hashmap

• Implements doubly-linked list.

Page 29: Java  Collections Framework

Any questions?

Page 30: Java  Collections Framework

Collections Class

• Contains static methods for operating on collections and maps.

• Quite usefull :-)

Page 31: Java  Collections Framework

Arrays Class

• Contains static methods sorting and searching arrays, comparing arrays, and filling array elements.

Page 32: Java  Collections Framework

Additional Info

• Synchronized Collection classes can be found in java.util.Collections

Page 33: Java  Collections Framework

( the end )

Page 34: Java  Collections Framework

Credits

Material Adapted from:Java Programming, 5th ed. by Y.

Daniel Liang&

Java.sun.com