当前位置:文档之家› Java数据结构

Java数据结构


What is a Collections framework?

A framework is an extensive set of interfaces, abstract classes and concrete classes together with support tools Framework is provided in java.util package & comprises three parts: 1. Core interfaces 2. Set of implementations. 3. Utility methods
Link List


Elements have a value and links that identify adjacent elements in the sequence. Inserting or deleting elements are O(1) operations.
Collections
Data structures in Java
OBJECTIVE
g b u e D
“ WHEN TO USE WHICH DATA STRUCTURE ”
Data Structures
1. A data structure is an arrangement of data in a computer’s memory.
Array List

Stores element in a contiguous block of memory and automatically expandable.


The collection efficiently (O(1)) inserts and deletes elements at the rear of the list. Operations at Intermediate positions have O(n) efficiency.
Lacked interoperability.

Features of Collection framework

Reduces programming effort. Increases performance.


Provides interoperability between unrelated APIs.



Set The familiar set abstraction. No duplicates; May or may not be ordered. List Ordered collection, also known as a sequence. Duplicates permitted; Allows positional access Map A mapping from keys to values. Each key can map to at most one value (function).
Iterators

A collection provides an iterator which allows sequential access to the elements of a collection. Methods:
has Next() – check if there are still elements next() – return the next object and advance remove() – remove the currently pointed object
Faster software reuse.

Interfaces and implementation
Extends Implements
Ip
Set List HashSet SortedSet
HashMap
SortedMap
LinkedList
2. It includes list,stack,binary trees, hash tables, etc. 3. Algorithms manipulate the data in these structures in various ways such as searching and sorting.


List interface


An interface that extends the Collections interface. An ordered collection .
Stores element by position Includes index based operation.


Allows duplicate elements.
Concrete List Implementations

There are two concrete implementations of the List interface

LinkedList ArrayList

Which is best to use depends on specific needs.

Need of a framework????

Pre Java SDK1.2, Java provided a handful of data structures: Hash Table Vector Stack


These were good and easy to use, but they were not organized into a more general framework.
ArrayList
TreeMap
TreeSet
Interfaces
Collection Set, List

A group of objects.

May or may not be ordered;

May or may not contain duplicates.
Interface continued
相关主题