java/코드 리뷰

12. lang1 - (2) ObjectDemo2 (HashSet 맛보기 예제)

Astaroth아스 2020. 4. 23. 19:30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package lang1;
 
import java.util.HashSet;
 
public class ObjectDemo2 {
    public static void main(String[] args) {
        
        
        User user1 = new User(10"홍길동""010-1111-1111");
        User user2 = new User(10"홍길동""010-1111-1111");
        
        // HashSet : 객체를 여러 개 담을 수 있는 자료구조 객체
        // 동일한 객체를 중복 저장하지 않음
        HashSet<User> set = new HashSet<User>();
        
        set.add(user1);
        set.add(user2);
        
        System.out.println("Set에 저장된 객체 --> " + set);
    }
}