java util * ▫ Java 5 released ◇ Lots of changes about collections Collection ▫ Group of elements (references to objects) ▫ It is not specified whether they
Previous PDF | Next PDF |
[PDF] Java Collection Framework
java util * ▫ Java 5 released ◇ Lots of changes about collections Collection ▫ Group of elements (references to objects) ▫ It is not specified whether they
[PDF] Les collections en Java - Université de Genève
Les collections en Java - Collection ❖ Définies à partir de la racine Interface Collection ou E est le type des éléments de la collection ❖ Les classes
[PDF] Microsoft PowerPoint - MVCDataSourceV1ppt - Les pages perso
modèle doit être sous la forme d'un java bean © Philippe GENOUD Collection notesEtudiant (int numEtud, String matiere) void updateNote (Note n)
[PDF] Les collections - IGM
L'interface java util Collection est l'interface de base de toutes les structures de donnée qui stocke des éléments Il existe 4 sous-interfaces – Set, ensemble
[PDF] (Microsoft PowerPoint - Pr\351sentation_Composite) - DevLOG
Collection; import java util Iterator; public abstract class Component { public void operation(){ System out println("Opération par défaut"); } // Ce sont les objets
[PDF] JAVA GENERICS
24 mar 2016 · /* Remove o fromthe collection; return true if * the collection is changed */ boolean remove(Object o); } 4 Java Collections
[PDF] Présentation PowerPoint - pagesperso
Syntaxe très proche de C++ et Java • C'est un langage très Java n'a pas de mode unsafe permettant l'arithmétique Implémentation d'une collection de livre
[PDF] Langage JAVA - Erick STATTNER
Sommaire 1 Introduction au concept de POO 2 Classes et Objets 3 Héritage et polymorphisme 4 Collections 5 Interfaces Graphiques 3
[PDF] OBJECT ORIENTED PROGRAMMING - IARE
A class is thus a collection of objects of similar type for example: mango, apple, and In Java, class “Object” is the base class to all other classes – If we do not
[PDF] java collections hands on
[PDF] java collections interview questions pdf
[PDF] java collections lecture notes
[PDF] java collections notes by durga sir
[PDF] java collections problems
[PDF] java collections programming exercises
[PDF] java collections tutorialspoint pdf
[PDF] java collections w3resource
[PDF] java compareto custom object
[PDF] java compareto null object
[PDF] java compareto nullable objects
[PDF] java compareto object method
[PDF] java compareto se8
[PDF] java compareto two objects
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