Презентация Java Collections Framework онлайн
На нашем сайте вы можете скачать и просмотреть онлайн доклад-презентацию на тему Java Collections Framework абсолютно бесплатно. Урок-презентация на эту тему содержит всего 63 слайда. Все материалы созданы в программе PowerPoint и имеют формат ppt или же pptx. Материалы и темы для презентаций взяты из открытых источников и загружены их авторами, за качество и достоверность информации в них администрация сайта не отвечает, все права принадлежат их создателям. Если вы нашли то, что искали, отблагодарите авторов - поделитесь ссылкой в социальных сетях, а наш сайт добавьте в закладки.
Презентации » Устройства и комплектующие » Java Collections Framework
Оцените!
Оцените презентацию от 1 до 5 баллов!
- Тип файла:ppt / pptx (powerpoint)
- Всего слайдов:63 слайда
- Для класса:1,2,3,4,5,6,7,8,9,10,11
- Размер файла:455.52 kB
- Просмотров:80
- Скачиваний:0
- Автор:неизвестен
Слайды и текст к этой презентации:
№5 слайд
![Store of Data Structure cont.](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img4.jpg)
Содержание слайда: Store of Data Structure (cont.)
Linked list is a data structure consisting of a group of nodes. Each node is composed of a datum and a reference to the next node in the sequence. This structure allows for efficient insertion or removal of elements from any position in the sequence.
№9 слайд
![The Limitation of Arrays An](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img8.jpg)
Содержание слайда: The Limitation of Arrays
An array is a very useful type in Java but it has its restrictions:
once an array is created it must be sized, and this size is fixed;
it contains no useful pre-defined methods.
Java comes with a group of generic collection classes that grow as more elements are added to them, and these classes provide lots of useful methods.
This group of collection classes are referred to as the Java Collections Framework.
№10 слайд
![What is a Collections](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img9.jpg)
Содержание слайда: What is a Collections Framework?
A unified architecture for representing and manipulating collections.
Includes:
– Interfaces: A hierarchy of abstract data types.
– Implementations
– Algorithms: The methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces.
№14 слайд
![Collection lt E gt public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img13.jpg)
Содержание слайда: Collection<E>
public interface Collection<E> extends Iterable<E> {
// Basic operations
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); //optional
boolean remove(Object element); //optional
Iterator<E> iterator();
// Bulk operations
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); //optional
boolean removeAll(Collection<?> c); //optional
boolean retainAll(Collection<?> c); //optional
void clear(); //optional
// Array operations
Object[] toArray();
<T> T[] toArray(T[] a);
}
№15 слайд
![Set Set a collection that](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img14.jpg)
Содержание слайда: Set
Set — a collection that cannot contain duplicate elements
This interface models the mathematical set abstraction and is used to represent sets, such as the cards comprising a poker hand, the courses making up a student's schedule, or the processes running on a machine
№16 слайд
![Set lt E gt methods public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img15.jpg)
Содержание слайда: Set<E> (methods)
public interface Set<E> extends Collection<E> {
// Basic operations
int size();
boolean isEmpty();
boolean contains(Object element);
boolean add(E element); //optional
boolean remove(Object element); //optional
Iterator<E> iterator();
// Bulk operations
boolean containsAll(Collection<?> c);
boolean addAll(Collection<? extends E> c); //optional
boolean removeAll(Collection<?> c); //optional
boolean retainAll(Collection<?> c); //optional
void clear(); //optional
// Array Operations
Object[] toArray();
<T> T[] toArray(T[] a);
}
№18 слайд
![List lt E gt methods public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img17.jpg)
Содержание слайда: List<E> (methods)
public interface List<E> extends Collection<E> {
// Positional access
E get(int index);
E set(int index, E element); //optional
boolean add(E element); //optional
void add(int index, E element); //optional
E remove(int index); //optional
boolean addAll(int index,
Collection<? extends E> c); //optional
// Search
int indexOf(Object o);
int lastIndexOf(Object o);
// Iteration
ListIterator<E> listIterator();
ListIterator<E> listIterator(int index);
// Range-view
List<E> subList(int from, int to);
}
№22 слайд
![Queue Queue a collection used](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img21.jpg)
Содержание слайда: Queue
Queue — a collection used to hold multiple elements prior to processing. Besides basic Collection operations, a Queue provides additional insertion, extraction, and inspection operations
Queues typically, but do not necessarily, order elements in a FIFO (first-in-first-out) manner
№26 слайд
![Deque lt E gt methods public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img25.jpg)
Содержание слайда: Deque<E> (methods)
public interface Deque<E> extends Queue<E> {
element()
add(E e) (addLast(E e))
offer(E e) (offerLast(E e)), offerFirst(E e)
peek()* (peekFirst()), peekLast()
getFirst(), getLast()
remove() (removeFirst()), removeFirstOccurrence(Object o),
removeLast(), removeLastOccurrence(Object o)
poll() (pollFirst()), pollLast()
contains(Object o)
iterator()
descendingIterator()
size()
pop() (removeFirst())
push(E e) (addFirst(E e))
}
from Queue, from Stack
№28 слайд
![SortedSet lt E gt methods](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img27.jpg)
Содержание слайда: SortedSet<E> (methods)
public interface SortedSet<E> extends Set<E> {
// Range-view
SortedSet<E> subSet(E fromElement, E toElement);
SortedSet<E> headSet(E toElement);
SortedSet<E> tailSet(E fromElement);
// Endpoints
E first();
E last();
// Comparator access
Comparator<? super E> comparator();
}
№29 слайд
![Map An object that maps keys](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img28.jpg)
Содержание слайда: Map
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value
The Map interface provides three collection views, which allow a map's contents to be viewed as a set of keys, collection of values, or set of key-value mappings
№30 слайд
![Map lt K,V gt methods public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img29.jpg)
Содержание слайда: Map<K,V> (methods)
public interface Map<K,V> {
// Basic operations
V put(K key, V value);
V get(Object key);
V remove(Object key);
boolean containsKey(Object key);
boolean containsValue(Object value);
int size();
boolean isEmpty();
// Bulk operations
void putAll(Map<? extends K, ? extends V> m);
№32 слайд
![Map.Entry public interface](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img31.jpg)
Содержание слайда: Map.Entry
public interface Entry {
K getKey();
V getValue();
V setValue(V value);
}
Map<String, String> map = new HashMap<String, String>();
map.put("1", "a");
map.put("2", "b");
map.put("3", "c");
for( Entry<String, String> entry : map.entrySet() ) {
if( "2".equals( entry.getKey() ) )
entry.setValue( "x" );
}
№35 слайд
![Implementations JDK provides](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img34.jpg)
Содержание слайда: Implementations
JDK provides implementations of each interface.
All implementations permit null elements, keys and values
All are Serializable, and all support a public clone method
Each one is unsynchronized
If you need a synchronized collection, the synchronization wrappers allow any collection to be transformed into a synchronized collection
№36 слайд
![HashSet, TreeSet,](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img35.jpg)
Содержание слайда: HashSet, TreeSet, LinkedHashSet
The two general purpose Set implementations are HashSet and TreeSet (and LinkedHashSet which is between them)
HashSet is much faster but offers no ordering guarantees.
If in-order iteration is important use TreeSet.
Iteration in HashSet is linear in the sum of the number of entries and the capacity. It's important to choose an appropriate initial capacity if iteration performance is important. The default initial capacity is 101. The initial capacity may be specified using the int constructor. To allocate a HashSet whose initial capacity is 17:
Set s= new HashSet(17);
№38 слайд
![ArrayList and LinkedList The](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img37.jpg)
Содержание слайда: ArrayList and LinkedList
The two general purpose List implementations are ArrayList and LinkedList . ArrayList offers constant time positional access, and it's just plain fast, because it does not have to allocate a node object for each element in the List, and it can take advantage of the native method System.arraycopy when it has to move multiple elements at once
If you frequently add elements to the beginning of the List, or iterate over the List deleting elements from its interior, you might want to consider LinkedList. These operations are constant time in a LinkedList but linear time in an ArrayList. Positional access is linear time in a LinkedList and constant time in an ArrayList
№39 слайд
![HashMap, TreeMap,](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img38.jpg)
Содержание слайда: HashMap, TreeMap, LinkedHashMap
The two general purpose Map implementations are HashMap and TreeMap.
And LinkedHashMap (similar to LinkedHashSet)
The situation for Map is exactly analogous to Set
If you need SortedMap operations you should use TreeMap; otherwise, use HashMap
№40 слайд
![The Legacy Collection Types](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img39.jpg)
Содержание слайда: The Legacy Collection Types
Enumeration
Analogous to Iterator.
Vector
Analogous to ArrayList, maintains an ordered list of elements that are stored in an underlying array.
Stack
Analogous of Vector that adds methods to push and pop elements.
Dictionary
Analogous to the Map interface, although Dictionary is an abstract class, not an interface.
Hashtable
Analogous HashMap.
Properties
A subclass of Hashtable. Maintains a map of key/value pairs where the keys and values are strings. If a key is not found in a properties object a “default” properties object can be searched.
№43 слайд
![Ordering and Sorting There](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img42.jpg)
Содержание слайда: Ordering and Sorting
There are two ways to define orders on objects.
Each class can define a natural order among its instances by implementing the Comparable interface.
Arbitrary orders among different objects can be defined by comparators, classes that implement the Comparator interface.
№44 слайд
![The Comparable Interface The](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img43.jpg)
Содержание слайда: The Comparable Interface
The Comparable interface consists of a single method:
public interface Comparable<T> {
public int compareTo(T o);
}
The compareTo method compares the receiving object with the specified object, and returns a negative integer, zero, or a positive integer as the receiving object is less than, equal to, or greater than the specified Object.
№46 слайд
![Comparator A Comparator is an](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img45.jpg)
Содержание слайда: Comparator
A Comparator is an object that encapsulates an ordering. Like the Comparable interface, the Comparator interface consists of a single method:
public interface Comparator<T> {
int compare(T o1, T o2);
}
The compare method compares its two arguments, returning a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
№47 слайд
![Live Code . Comparable class](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img46.jpg)
Содержание слайда: Live Code . Comparable
class HDTV implements Comparable<HDTV> {
private int size;
private String brand;
public HDTV(int size, String brand) {
this.size = size;
this.brand = brand;
}
public int getSize() { return size;}
public void setSize(int size) {this.size = size; }
public String getBrand() { return brand;}
public void setBrand(String brand) {this.brand = brand; }
@Override
public int compareTo(HDTV tv) {
if (this.getSize() > tv.getSize()) return 1;
else if (this.getSize() < tv.getSize()) return -1;
else return 0;
}
}
№48 слайд
![Live Code . Comparable public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img47.jpg)
Содержание слайда: Live Code . Comparable
public class Main {
public static void main(String[] args) {
HDTV tv1 = new HDTV(55, "Samsung");
HDTV tv2 = new HDTV(60, "Sony");
HDTV tv3 = new HDTV(42, "Panasonic");
ArrayList<HDTV> al = new ArrayList<HDTV>();
al.add(tv1);
al.add(tv2);
al.add(tv3);
Collections.sort(al);
for (HDTV a : al) {
System.out.println(a.getBrand());
}
}
}
№49 слайд
![Live Code . Comparator class](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img48.jpg)
Содержание слайда: Live Code . Comparator
class HDTV {
private int size;
private String brand;
public HDTV(int size, String brand) {
this.size = size;
this.brand = brand;
}
public int getSize() { return size;}
public void setSize(int size) {this.size = size; }
public String getBrand() { return brand;}
public void setBrand(String brand) {this.brand = brand; }
}
№50 слайд
![Live Code . Comparator class](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img49.jpg)
Содержание слайда: Live Code . Comparator
class SizeComparator implements Comparator<HDTV> {
@Override
public int compare(HDTV tv1, HDTV tv2) {
int tv1Size = tv1.getSize();
int tv2Size = tv2.getSize();
if (tv1Size > tv2Size) {
return 1;
} else if (tv1Size < tv2Size) {
return -1;
} else {
return 0;
}
}
}
class BrandComparatorDescOrder implements Comparator<HDTV> {
@Override
public int compare(HDTV tv1, HDTV tv2) {
return tv2.getBrand().compareTo(tv1.getBrand())
}
}
№51 слайд
![Live Code . Comparator public](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img50.jpg)
Содержание слайда: Live Code . Comparator
public class Main {
public static void main(String[] args) {
HDTV tv1 = new HDTV(55, "Samsung");
HDTV tv2 = new HDTV(60, "Sony");
HDTV tv3 = new HDTV(42, "Panasonic");
ArrayList<HDTV> al = new ArrayList<HDTV>();
al.add(tv1);
al.add(tv2);
al.add(tv3);
Collections.sort(al, new SizeComparator());
for (HDTV a : al) {
System.out.println(a.getBrand());
}
Collections.sort(al, new BrandComparatorDescOrder());
for (HDTV a : al) {
System.out.println(a.getBrand());
}
}
}
№52 слайд
![Other implementations in the](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img51.jpg)
Содержание слайда: Other implementations in the API
Wrapper implementations delegate all their real work to a specified collection but add (or remove) extra functionality on top of what the collection offers.
Synchronization Wrappers
Unmodifiable Wrappers
Convenience implementations are mini-implementations that can be more convenient and more efficient than general-purpose implementations when you don't need their full power
List View of an Array
Immutable Multiple-Copy List
Immutable Singleton Set
Empty Set, List, and Map Constants
№53 слайд
![Synchronization wrappers The](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img52.jpg)
Содержание слайда: Synchronization wrappers
The synchronization wrappers add automatic synchronization (thread-safety) to an arbitrary collection. There is one static factory method for each of the six core collection interfaces:
public static Collection synchronizedCollection(Collection c);
public static Set synchronizedSet(Set s);
public static List synchronizedList(List list);
public static Map synchronizedMap(Map m);
public static SortedSet synchronizedSortedSet(SortedSet s);
public static SortedMap synchronizedSortedMap(SortedMap m);
Each of these methods returns a synchronized (thread-safe) Collection backed by the specified collection.
№54 слайд
![Unmodifiable wrappers](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img53.jpg)
Содержание слайда: Unmodifiable wrappers
Unmodifiable wrappers take away the ability to modify the collection, by intercepting all of the operations that would modify the collection, and throwing an UnsupportedOperationException. The unmodifiable wrappers have two main uses:
To make a collection immutable once it has been built.
To allow "second-class citizens" read-only access to your data structures. You keep a reference to the backing collection, but hand out a reference to the wrapper. In this way, the second-class citizens can look but not touch, while you maintain full access.
№55 слайд
![Unmodifiable wrappers cont.](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img54.jpg)
Содержание слайда: Unmodifiable wrappers(cont.)
There is one static factory method for each of the six core collection interfaces:
public static Collection unmodifiableCollection(Collection c);
public static Set unmodifiableSet(Set s);
public static List unmodifiableList(List list);
public static Map unmodifiableMap(Map m);
public static SortedSet unmodifiableSortedSet(SortedSet s);
public static SortedMap unmodifiableSortedMap(SortedMap m);
№56 слайд
![Singleton static lt T gt Set](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img55.jpg)
Содержание слайда: Singleton
static <T> Set<T>Collections.singleton(T e) returns an immutable set containing only the element e
This is handy when you have a single element but you would like to use a Set operation
c.removeAll(Collections.singleton(e));
will remove all occurrences of e from the Collection c
№57 слайд
![The Collections Toolbox The](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img56.jpg)
Содержание слайда: The Collections Toolbox
The collections framework also provides polymorphic versions of algorithms you can run on collections.
Sorting
Shuffling
Routine Data Manipulation
Reverse
Fill copy
etc.
Searching
Binary Search
Composition
Frequency
Disjoint
Finding extreme values
Min
Max
№58 слайд
![Concurrent Collections](/documents_6/e2f0ebaef3fdac842e78fb82119abea9/img57.jpg)
Содержание слайда: Concurrent Collections
ConcurrentReaderHashMap An analog of java.util.Hashtable that allows retrievals during updates.
ConcurrentHashMap An analog of java.util.Hashtable that allows both concurrent retrievals and concurrent updates.
CopyOnWriteArrayList A copy-on-write analog of java.util.ArrayList
CopyOnWriteArraySet A java.util.Set based on CopyOnWriteArrayList.
SyncCollection A wrapper class placing either Syncs or ReadWriteLocks around java.util.Collection
SyncSet A wrapper around java.util.Set
SyncSortedSet A wrapper around java.util.SortedSet
SyncList A wrapper around java.util.List
SyncMap A wrapper around java.util.Map
SyncSortedMap A wrapper around java.util.SortedMap
Скачать все slide презентации Java Collections Framework одним архивом:
Похожие презентации
-
Программирование на Java. Collections Framework - фреймверк коллекций объектов. (Лекция 7. 1)
-
Java SE 4. Collections. Иерархия интерфейсов
-
Создание приложения, используя Spring Framework. Java. (Лекция 23)
-
Generic Collections Java Core
-
Интерфейс Java Collection
-
Java. SE. 06. Generic and collections
-
Объектно-ориентированное программирование. Collections Framework. (Занятие 7)
-
Лекция 7. Collections . NET Framework
-
5. Java collections and Generics. 3. Generics
-
ИТ инициатива Java 8