Please Enable JavaScript!
Mohon Aktifkan Javascript![ Enable JavaScript ]

Set 인터페이스, Map 인터페이스 - HashSet

2010. 3. 24. 11:40programming/jsp

728x90

 
u집합(Set) 원소의 중복을 허용하지 않는다.
uHashSet
nHashSet 해쉬 테이블에 원소를 저장하기 때문에 성능면에서 가장 우수하다. 하지만 원소들의 순서가 일정하지 않은 단점이 있다

 
Map 인터페이스 - HashMap 
사전과 같은 자료 구조
(key) (value) 매핑된다.

강아지를 예를 들면.

ㄱ - 키(key)
강아지 - 값(value)

HashMap 사용 예제

 
class Student {
   int number;
   String name;
   public Student(int number, String name) {  this.number = number;       this.name = name;}
   public String toString() {   return name;  }}
public class MapTest {
   public static void main(String[] args) {
           Map<String, Student> st = new HashMap<String, Student>(); //<키타입, 데이터 타입>
//1. 상속 2. 구현 Map 이 상위클래스 HashMap이 하위클래스 Map 상위클래스 타입으로 HashMap이라는 하위클래스로 구현함.
           st.put("20090001", new Student(20090001, "구준표")); //항목 저장
// 키(key) ,               값(value)
           st.put("20090002", new Student(20090002, "금잔디"));
           st.put("20090003", new Student(20090003, "윤지후"));
           System.out.println(st); // 모든 항목을 출력한다.
           st.remove("20090002"); // 하나의 항목을 삭제한다.
           st.put("20090003", new Student(20090003, "소이정")); // 하나의 항목을 대치한다.
           System.out.println(st.get("20090003")); // 값을 참조한다.
            // 모든 항목을 방문한다.
           for (Map.Entry<String, Student> s : st.entrySet()) {
                   String key = s.getKey();
                   Student value = s.getValue();
                   System.out.println("key=" + key + ", value=" + value);
               }
       }
}


1.왜 데이터를 Object 참조형 변수에 저장하는 것이 위험할 있는가?
   타입 미스 매치
1.2.ArrayList LinkedList 차이점은 무엇인가?
가변배열 / 연결리스트구조
ArrayList는 다음데이터 그전데이터 링크가 없음
LinkedList 는 앞뒤 데이터 정보 링크를 가진다.
1.3.어떤 경우에 LinkedList 사용하여야 하는가?
삽입 ,삭제가 빈번히 발생할 LinkedList 사용한다.
728x90

'programming > jsp' 카테고리의 다른 글

request.getParameter()  (0) 2010.03.31
AddressLinkedList < 03/26 수업중 >  (0) 2010.03.26
1. 상품 목록을 저장하고 합계 출력하기 – ArrayList 사용  (0) 2010.03.24
반복자(iterator)  (0) 2010.03.24
제너릭  (0) 2010.03.19