[PDF] [PDF] Java Collection Framework





Previous PDF Next PDF



Collections en Java

Une collection gère un groupe d'un ensemble d'objets d'un type donné ; ou bien (Java 2) est apparu le framWork de collections qui tout en gardant les ...



Programmation Objet Java–Collections

Java–Collections Dans la bibliothèque Java on retrouve ... Désavantage de l'interface Collection : trop générale ne permet que d'accès basique sur les.



Les collections en Java

Les collections en Java. ? Les interfaces racine Collection et Map. ? Digression 1: les interfaces Java. ? Digression 2: les classes génériques.



VIII- Les collections.pdf

A quoi cela sert ? ? Par exemple java.util.Arrays.sort() demande à ce que le tableau contienne des éléments.



Introduction to the Java collections Framework • Lists • Sets • Maps

The Java Collections Framework is a library of classes and interfaces for working with collections of objects. A collection is an object which can store 



Les Collections

Les Collections. Cours Java - F. Michel Une collection est un objet qui regroupe d'autres ... un répertoire téléphonique -> une collection de noms.



Collections et tables de hachage

ensembles : collections d'objets sans répétition de valeurs les collections sont typées depuis java 1.5 une interface définit le contrat des collections.



Chapitre 8 Collections en Java

HashSet: les éléments sont rangés suivant une méthode de hachage. import java.util.*; public class SetExample { public static void main(String args[]) {. Set 





JAVA : Syntaxe de base

Les fichiers sources (xxx.java) sont transformés en un langage intermédiaire (xxx.class) par un compilateur (commande javac) qui peut être interprété soit par 



[PDF] Collections en Java

Une collection gère un groupe d'un ensemble d'objets d'un type donné ; ou bien c'est un objet qui sert à stocker d'autres objets



[PDF] Les collections en Java - Université de Genève

Digression 1: les interfaces Java ? Digression 2: les classes génériques ? Les collections de données: 1 Les tableaux dynamiques: la classe ArrayList



[PDF] Cours 8 : Les collections Inspiré du livre de Claude Delannoy - Loria

1 Java Licence Professionnelle CISI 2009-2010 Cours 8 : Les collections Ainsi là encore pour des méthodes de type String File



[PDF] Collections Collections Collections javautilArrayList

Il y a deux manières d'ajouter un élément ? à la fin d'un ArrayList avec la méthode boolean add(Object newElement) ? à une position donnée



[PDF] Les collections Java - LIRMM

Algorithmes Conclusion Les collections Java 1 / 34 Cours Java - F Michel Deque : file où on peut traiter le début ou la fin (e g LIFO)



[PDF] listes Collections - CS-108

1 les listes (lists) collection ordonnée dans laquelle un élément donné peut apparaître plusieurs nombre de collections dans ce qui s'appelle le Java



[PDF] Les collections Les collections

9 jui 2014 · 1 Chapitre 7: Les collections ? Définition ? Les classes: Un vecteur est un objet de type Vector (classe hérité de Java 1 0)



[PDF] Java Collection Framework

Java 5 released! ? Lots of changes about collections From Java 5 all collection interfaces true (or false) provided that no information used in

  • Comment faire une collection en Java ?

    La création d'une collection consiste en son instanciation, et l'utilisation de sa méthode add(T) . Voyons ceci sur un exemple. // création d'une collection de String Collection<String> collection = new ArrayList<String>() ; // ajout d'éléments à cette collection collection. add("un") ; collection.
  • Les collections sont des objets qui permettent de gérer des ensembles d'objets. Ces ensembles de données peuvent être définis avec plusieurs caractéristiques : la possibilité de gérer des doublons, de gérer un ordre de tri, etc. Une collection est un regroupement d'objets qui sont désignés sous le nom d'éléments.

Java Collection Framework

Version March 2009

2

Framework

ƒInterfaces (ADT, Abstract Data Types)

ƒImplementations (of ADT)

ƒAlgorithms (sort)

ƒjava.util.*

ƒJava 5 released!

ŠLots of changes about collections

3

Interfaces

Collection

SetList

Map

SortedSet

SortedMap

Group containers

Associative containers

Queue

Iterable

4

Implementations

TreeSet

TreeMapArray

List

Linked

List

HashMap

Linked

HashMap

Linked

HashSet

HashSet

Map

Sorted

Map

Collection

SetList

Sorted

Set

Queue

Priority

Queue 5

Internals

LinkedList

Linked list

LinkedHashMapTreeMapHashMapMap

ArrayListList

LinkedHashSet TreeSetHashSetSet

Hash table

Linked list

Balanced

tree

Resizable

array Hash table interface data structure classes 6

Collection

ƒGroupof elements (referencesto objects)

ƒIt is not specified whether they are

ŠOrdered / not ordered

ŠDuplicated / not duplicated

ƒFollowing constructors are common to all

classes implementing Collection

ŠT()

ŠT(Collection c)

7

Collection interface

ƒint size()

ƒboolean isEmpty()

ƒboolean contains(Object element)

ƒboolean containsAll(Collection c)

ƒboolean add(Object element)

ƒboolean addAll(Collection c)

ƒboolean remove(Object element)

ƒboolean removeAll(Collection c)

ƒvoid clear()

ƒObject[] toArray()

ƒIterator iterator()

8

Collection example

Collection persons =

new LinkedList(); persons.add QHR 3HUVRQ³$OLŃH´

System.out.println( persons.size() );

Collection copy =

new TreeSet(); copy.addAll(persons);//new TreeSet(persons)

Person[] array = copy.toArray();

System.out.println( array[0] );

9 Map

ƒAn object that associates keys to values

HBJB 661 ҧ 3HUVRQ

ƒKeys and values must be objects

ƒKeysmust be unique

ƒOnly one value per key

ƒFollowing constructors are common to all

collection implementers

ŠT()

ŠT(Map m)

10

Map interface

ƒObject put(Object key, Object value)

ƒObject get(Object key)

ƒObject remove(Object key)

ƒboolean containsKey(Object key)

ƒboolean containsValue(Object value)

ƒpublic Set keySet()

ƒpublic Collection values()

ƒint size()

ƒboolean isEmpty()

ƒvoid clear()

11

Map example

Map people =new HashMap(); people.put ³$IF607´ //ssnQHR 3HUVRQ³$OLŃH´ ³6PLPO´ people.put ³5%7*51´ //ssnQHR 3HUVRQ³5RNHUP´ ³*UHHQ´

Person bob = people.get³5%7*51´

if( bob == null)

6\VPHPBRXPBSULQPOQ ³1RP IRXQG´

int populationSize = people.size(); 12

Generic collections

ƒFrom Java 5, all collection interfaces

and classes have been redefined as

Generics

ƒUse of generics lead to code that is

Šsafer

Šmore compact

Šeasier to understand

Šequally performing

13

Generic list -excerpt

public interface List{ void add(E x);

Iterator iterator();

public interface Iterator{

E next();

booleanhasNext(); 14

Example

ƒUsing a list of Integers

ŠWithout generics ( ArrayListlist )

list.add(0, new Integer(42));intn= ((Integer)(list.get(0))).intValue();

ŠWith generics ( ArrayList list )

list.add(0, new Integer(42));intn= ((Integer)(list.get(0))).intValue();

Š+ autoboxing( ArrayList list )

list.add(0,new Integer(42));inttotal = list.get(0).intValue();

Group containers

(Collections)Collection

SetList

SortedSet

Queue

16 List

ƒCan contain duplicateelements

ƒInsertion orderis preserved

ƒUser can define insertion point

ƒElements can be accessed by position

ƒAugments Collection interface

17

List additional methods

ƒObject get(int index)

ƒObject set(int index, Object element)

ƒvoid add(int index, Object element)

ƒObject remove(int index)

ƒboolean addAll(int index, Collection c)

ƒint indexOf(Object o)

ƒint lastIndexOf(Object o)

ƒList subList(int fromIndex, int toIndex)

18

List implementations

ArrayList

ƒget(n)

ŠConstant time

ƒInsert (beginning)

and delete while iterating

ŠLinear

LinkedList

ƒget(n)

ŠLinear time

ƒInsert (beginning)

and delete while iterating

ŠConstant

19

List implementations

ƒArrayList

ŠArrayList()

ŠArrayList(int initialCapacity)

ŠArrayList(Collection c)

Švoid ensureCapacity(int minCapacity)

ƒLinkedList

Švoid addFirst(Object o)

Švoid addLast(Object o)

ŠObject getFirst()

ŠObject getLast()

ŠObject removeFirst()

ŠObject removeLast()

20

Example I

LinkedListll =

new LinkedList(); ll.add(new Integer(10)); ll.add(new Integer(11)); ll.addLast(new Integer(13)); ll.addFirst(new Integer(20)); //20, 10, 11, 13 21

Example II

Car[] garage = new Car[20];

garage[0] = new Car(); garage[1] = new ElectricCar(); garage[2] = new ElectricCar(); garage[3] = new Car(); for(int i=0; iNull pointer error

Listgarage = new ArrayList(20);

garage.set( 0, new Car() ); garage.set( 1, new ElectricCar() ); garage.set( 2, new ElectricCar() ); garage.set( 3, new Car()); for(int i; iCar c = garage.get(i); c.turnOn(); 22

Example III

List l = new ArrayList(2); // 2 refs to null

l.add(new Integer(11)); // 11 in position 0 l.add(0, new Integer(13)); // 11 in position 1 l.set(0, new Integer(20)); // 13 replaced by 20 l.add(9, new Integer(30)); // NO: out of bounds l.add(new Integer(30)); // OK, size extended 23
Queue

ƒCollection whose elements have an

order (

Šnot and ordered collection though

ƒDefines a headposition where is the

first element that can be accessed

Špeek()

Špoll()

24

Queue implementations

ƒLinkedList

Šhead is the first element of the list

ŠFIFO: Fist-In-First-Out

ƒPriorityQueue

Šhead is the smallest element

25

Queue example

Queue fifo =

new LinkedList();

Queue pq =

new PriorityQueue(); fifo.add(3); pq.add(3); fifo.add(1); pq.add(1); fifo.add(2); pq.add(2);

System.out.println(fifo.peek()); // 3

System.out.println(pq.peek());// 1

26
Set

ƒContains no methods other than those

inherited from Collection

ƒadd()has restriction that no duplicate

elementsare allowed

Še1.equals(e2) == false

e1,e2

ƒIterator

ŠThe elements are traversed in no

particular order

The equals() Contract

It is reflexive: x.equals(x) == true

It is symmetric: x.equals(y) == y.equals(x)

It is transitive: for any reference values x, y, and z, if x.equals(y) == true AND y.equals(z) == true => x.equals(z) == true It is consistent: for any reference values x and y, multiple invocations of x.equals(y) consistently return true (or false), provided that no information used in equals comparisons on the object is modified. x.equals(null) == false hashCode

The hashCode() contract

The hashCode() method must consistently

return the same int, if no information used in equals() comparisons on the object is modified.

If two objects are equal for equals() method,

then calling the hashCode() method on the twoquotesdbs_dbs12.pdfusesText_18
[PDF] parcourir une liste java

[PDF] les collection en java

[PDF] hashtable java open classroom

[PDF] guerre de tranchées date

[PDF] exercices corrigés sur les collections en java pdf

[PDF] java liste vide

[PDF] cours php pdf complet

[PDF] parcours 3éme année du cycle secondaire collégial

[PDF] référentiel parcours avenir

[PDF] contraintes du parcours avenir

[PDF] parcours avenir folios

[PDF] les grandes phases de la seconde guerre mondiale

[PDF] epi parcours avenir stage

[PDF] l'immigration irlandaise aux etats unis

[PDF] immigration aux etats unis au 20eme siecle