본문 바로가기

B1:기초 Basement

Java::Collections Framework

반응형
Sun 홈페이지의 참고문서 링크
Tutorials & Code Camps > Introduction to the Collections Framework
About This Short Course
Java : Tutorials and Online Training


Collection Framework 개괄

인터페이스클래스특징
SetHashSet, TreeSet중복된 데이터를 허용하지 않음
데이터의 순서가 없다
ListArrayList, LinkedList, Vector중복된 데이터를 허용
데이터의 순서가 있다
MapHashMap,TreeMap, Hashtable요소에 대한 고유의 key가 존재함
key는 중복될 수 없다.


[표 15-1] 자료 구조 관련 클래스

java.util.Random Class
여러 형태(double형,float형,int형,long형,true-false 등)의 난수를 발생시킴

java.util.Arrays Class
배열의 정렬,비교,검색 등의 기능을 제공. 모든 메소드가 static이다.

java.util.StringTokenizer
문자열에서 단어를 분리하는 기능.

java.util.Calendar
달력기능을 제공하는 클래스. 날짜와 관련된 메소드 제공.


Collections API 의 interface 들
java.util.Collection : 순서에 관계없는 객체들의 단순한 모임
java.util.Set : 중복되지 않는 객체들의 집합, Collection 상속
java.util.List : 순차적으로 나열된 구조,마지막 추가데이터 마지막에 저장, Collection 상속
java.util.Map : key 와 value 로 이루어진 구조
java.util.SortedSet : 값들이 정렬된 Set , Set을 상속
java.util.SortedMap : key 가 정렬된 Map, Map을 상속


Collections API 의 class 들
java.util.Vector : 크기가 가변적인 배열
java.util.HashSet : set 인터페이스(중복되는 값을 허용하지 않음)의 기본구현
java.util.TreeSet : HashSet과 같으나 정렬기능이 추가됨. SortedSet구현
java.util.ArrayList : 크기가 가변적인 List
java.util.LinkedList : Double Linked List를 구현한 클래스. 삽입/삭제가 잦은 경우 유용.
                            리스트의 맨 처음/끝단에 자료를 삽입/삭제 가능
java.util.HashMap : Map 인터페이스(키-동일값 불가-와 값으로 이루어짐)의 기본구현
java.util.TreeMap : HashMap 과 같으나 키값을 이용한 정렬기능 추가됨. SortedMap구현
java.util.Hashtable : Map 인터페이스를 구현하는 클래스. Java2이전에 많이 사용되었음.
                            HashMap과 동일


Mathematical Background

In common usage a collection is the same as the intuitive, mathamatical concept of a set. A set is just a group of unique items, meaning that the group contains no duplicates. The Collections Framework in fact includes a Set interface, and a number of concrete Set classes. But the formal notion of a set predates Java technology by a century, when the British mathematician George Boole defined it in formal logic. Most people learned some set theory in elementary school when introduced to "set intersection" and "set union" through the familiar Venn Diagrams:

Some real-world examples of sets include the following:

  • The set of uppercase letters 'A' through 'Z'
  • The set of nonnegative integers {0, 1, 2 ...}
  • The set of reserved Java programming language keywords {'import', 'class', 'public', 'protected'...}
  • A set of people (friends, employees, clients, ...)
  • The set of records returned by a database query
  • The set of Component objects in a Container
  • The set of all pairs
  • The empty set {}

These examples show the basic properties of sets:

  • Sets contains only one instance of each item
  • Sets may be finite or infinite
  • Sets can define abstract concepts

Sets are fundamental to logic, mathematics, and computer science, but also practical in everyday applications in business and systems. The idea of a "connection pool" is a set of open connections to a database server. Web servers have to manage sets of clients and connections. File descriptors provide another example of a set in the operating system.

A map is a special kind of set. It is a set of pairs, each pair representing a one-directional "mapping" from one element to another. Some examples of maps are:

  • The map of IP addresses to domain names (DNS)
  • A map from keys to database records
  • A dictionary (words mapped to meanings)
  • The conversion from base 2 to base 10

Like sets, the idea behind a map is much older than the Java programming language, older even than computer science. Sets and maps are important tools in mathematics and their properties are well-understood. People also long recognized the usefulness of solving programming problems with sets and maps. A language called SETL (Set Language) invented in 1969 included sets as one of its only primitive data types (SETL also included garbage collection--not widely accepted until Java technology developed in the 1990's). Although sets and maps appear in many languages including C++, the Collections Framework is perhaps the best designed set and map package yet written for a popular language. Users of C++ Standard Template Library (STL) and Smalltalk's collection hierarchy might argue that last point.

Also because they are sets, maps can be finite or infinite. An example of an infinite map is the conversion from base 2 to base 10. Unfortunately, the Collections Framework does not support infatuate maps--sometimes a mathematical function, formula or algorithm is preferred. But when a problem can be solved with a finite map, the Collections Framework provides the Java programmer with a useful API.

Because the Collections Framework has formal definitions for the classes Set, Collection, and Map, you'll notice the lower case words set, collection and map to distinguish the implementation from the concept.

반응형

'B1:기초 Basement' 카테고리의 다른 글

법::특별권력관계  (0) 2006.05.31
헌법 참고사이트  (0) 2006.05.31
WebLogic 참고자료  (0) 2006.05.31
IBM Library Server  (0) 2006.05.31
유니코드, Unicode  (0) 2006.05.30