Пређи на садржај

Java collections framework

С Википедије, слободне енциклопедије
Датум измене: 27. мај 2015. у 15:34; аутор: RushMinute (разговор | доприноси) (Нова страница: {{РУТ}} {{МАТФ042015}} ''''Java collections framework - JCF''' je skup klasa i interfejsova koji implementiraju č…)
(разл) ← Старија измена | Тренутна верзија (разл) | Новија измена → (разл)

'Java collections framework - JCF je skup klasa i interfejsova koji implementiraju često upotrebljivane kolekcije struktura podataka.[1]

Istorija

Implementacije kolekcija u verzijama Jave pre JDK 1.2 su sadržavale nekolicinu klasa struktura podataka, ali ne i .[2] Standardni načini za grupisanje Java objekata su bili pomoću nizova, Vector i Hashtable klasa, koje nije bilo lako proširiti.[3]

S obzirom na potrebu za dinamičnijim kolekcijama struktura podataka, razvijene su mnoge nezavisne biblioteke,[2] od kojih su najkorišćenije bile Dag Lijev (Doug Lea) Paket kolekcija (Collections package),[4] i ObjectSpace Generic Collection Library (JGL),[5] čija je svrha bila konzistentnost sa C++ Standard Template Library (STL).[6]

JCF je razvijen i dizajniran uglavnom od strane Džoš Bloka, i pojavio se u JDK 1.2. Koristi mnoge ideje i klase i Dag Lijevog Paketa kolekcija, koji tada biva prevaziđen..[4] Sun chose not to use the ideas of JGL, because they wanted a compact framework, and consistency with C++ was not one of their goals.[7]

Arhitektura

Skoro sve kolekcije nasle]uju od java.util.Collection interfejsa, koji definiše osnovne delove svake kolekcije. Interfejs uvodi add() i remove() metode za dodavanje i izbacivanje iz kolekcije. Neophodni su i toArray() metod, koji prevodi kolekciju u niz koji sadrži sve članove kolekcije, i contains() metod koji proverava da li kolekcija sadrži neki konkretan element. Ovaj interfejs nasleđuje od java.lang.Iterable interfejsa, čime se omogućuje obrada kolekcija pomoću for-each izraza. Sve kolekcije imaju iterator koji prolazi kroz sve elemente u kolekciji.

Liste

Stek

Red

Red sa dva kraja

Mapa

Skup

Proširenja za JCF

Reference

  1. ^ „Lesson: Introduction to Collections”. Oracle Corporation. Приступљено 2010-12-22. 
  2. ^ а б „Java Collections Framework” (PDF). IBM. Приступљено 2011-01-01. 
  3. ^ „Get started with the Java Collections Framework”. JavaWorld. 1998-01-11. Приступљено 2011-01-01. „'Before Collections made its most welcome debut, the standard methods for grouping Java objects were via the array, the Vector, and the Hashtable. All three of these collections have different methods and syntax for accessing members: arrays use the square bracket ([]) symbols, Vector uses the elementAt method, and Hashtable uses get and put methods.' 
  4. ^ а б Doug Lea. „Overview of the collections Package”. Приступљено 2011-01-01. „'The Sun Java Development Kit JDK1.2 finally includes a standard set of collection classes. While there are some design and implementation differences, the JDK1.2 package contains most of the same basic abstractions, structure, and functionality as this package. For this reason, this collections package will NOT be further updated' 
  5. ^ „Generic Collection Library for Java™”. Приступљено 2011-01-01. 
  6. ^ „Need a good set of abstract data structures? ObjectSpace's JGL packs a punch!”. JavaWorld. 1997-01-06. Приступљено 2011-01-01. „'As with Java itself, the Java Generic Library borrows heavily from the C++ camp: It takes the best from C++'s STL, while leaving the C++ warts behind. Most C++ programmers today will know of their STL, but few are managing to exploit its potential.' 
  7. ^ „The battle of the container frameworks: which should you use?”. JavaWorld. 1999-01-01. Приступљено 2011-01-01. „'Comparing ObjectSpace Inc.'s JGL and Sun's Collections Framework turns out to be like comparing apples and kiwi fruits. At first sight, the two frameworks seem to be competing for the same developers, but after a closer inspection it is clear that the two cannot be compared fairly without acknowledging first that the two frameworks have different goals. If, like Sun's documentation states, Collections is going to homogenize Sun's own APIs (core API, extensions, etc.), then clearly Collections has to be great news, and a good thing, even to the most fanatic JGL addict. Provided Sun doesn't break its promise in this area, I'll be happy to invest my resources in adopting Collections in earnest. '