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
Cours 8 : Les collections Inspiré du livre de Claude Delannoy
(c) Claude delannoy Programmer en Java
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
2Framework
Interfaces (ADT, Abstract Data Types)
Implementations (of ADT)
Algorithms (sort)
java.util.*
Java 5 released!
Lots of changes about collections
3Interfaces
Collection
SetList
Map
SortedSet
SortedMap
Group containers
Associative containers
Queue
Iterable
4 Implementations
TreeSet
TreeMapArray
ListLinked
ListHashMap
Linked
HashMap
Linked
HashSet
HashSet
Map
Sorted
Map
Collection
SetList
Sorted
Set
Queue
Priority
Queue 5Internals
LinkedList
Linked list
LinkedHashMapTreeMapHashMapMap
ArrayListList
LinkedHashSet TreeSetHashSetSet
Hash table
Linked list
Balanced
treeResizable
array Hash table interface data structure classes 6Collection
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 CollectionT()
T(Collection c)
7Collection 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()
8Collection example
Collection persons =
new LinkedListSystem.out.println( persons.size() );
Collection copy =
new TreeSetPerson[] array = copy.toArray();
System.out.println( array[0] );
9 MapAn 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 implementersT()
T(Map m)
10Map 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()
11Map example
MapPerson bob = people.get³5%7*51´
if( bob == null)6\VPHPBRXPBSULQPOQ ³1RP IRXQG´
int populationSize = people.size(); 12Generic collections
From Java 5, all collection interfaces
and classes have been redefined asGenerics
Use of generics lead to code that is
safer
more compact
easier to understand
equally performing
13Generic list -excerpt
public interface ListIterator iterator();
public interface IteratorE next();
booleanhasNext(); 14Example
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)CollectionSetList
SortedSet
Queue
16 List Can contain duplicateelements
Insertion orderis preserved
User can define insertion point
Elements can be accessed by position
Augments Collection interface
17List 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)
18List implementations
ArrayList
get(n)
Constant time
Insert (beginning)
and delete while iteratingLinear
LinkedList
get(n)
Linear time
Insert (beginning)
and delete while iteratingConstant
19List 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()
20Example I
LinkedListll =
new LinkedListExample 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; iListgarage = 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; iExample 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 23Queue
Collection whose elements have an
order (not and ordered collection though
Defines a headposition where is the
first element that can be accessedpeek()
poll()
24Queue implementations
LinkedList
head is the first element of the list
FIFO: Fist-In-First-Out
PriorityQueue
head is the smallest element
25Queue example
Queue fifo =
new LinkedListQueue pq =
new PriorityQueueSystem.out.println(fifo.peek()); // 3
System.out.println(pq.peek());// 1
26Set
Contains no methods other than those
inherited from Collectionadd()has restriction that no duplicate
elementsare allowede1.equals(e2) == false
e1,e2Iterator
The elements are traversed in no
particular orderThe 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 hashCodeThe 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] 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