Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter05 : TreeSet 본문

JAVA/chapter23_collection_framework

chapter05 : TreeSet

GAWON 2023. 5. 31. 09:13
package org.joonzis.ex;

import java.util.TreeSet;

public class Ex05_TreeSet {
	public static void main(String[] args) {
		
		// TreeSet 의 메소드를 사용하기 위해 Set 대신 TreeSet 사용
		TreeSet<String> set = new TreeSet<String>();
		
		set.add("airplane");
		set.add("apple");
		set.add("area");
		set.add("disc");
		set.add("dance");
		
		/*
		 * 1. 메소드 정의
		 * 
		 * headSet 	: 지정된 객체보다 작은 값의 객체들 반환
		 * subSet	: 범위 내의 검색 결과 반환
		 * tailSet	: 지정된 객체보다 큰 값의 객체들 반환
		 */
		System.out.println(set.headSet("b"));
		System.out.println(set.subSet("a", "aq"));
		System.out.println(set.tailSet("c"));
		
		
		TreeSet<Integer> setInt = new TreeSet<Integer>();
		
		setInt.add(10);
		setInt.add(20);
		setInt.add(30);
		setInt.add(40);
		setInt.add(50);
		
		System.out.println(setInt.headSet(15));
		System.out.println(setInt.subSet(15, 45));
		System.out.println(setInt.tailSet(35));
		
	
	}
}

'JAVA > chapter23_collection_framework' 카테고리의 다른 글

Test . collection_framework  (0) 2023.05.31
chapter06 : HashMap  (0) 2023.05.31
chapter04 : HashSet  (0) 2023.05.31
chapter03 : LinkedList  (0) 2023.05.31
chapter02 : iterator  (0) 2023.05.31