자바 SortedSet

개요[ | ]

Set은 중복을 허용하지 않으면서 저장 순서를 유지하는 방식
SortedSet은 원소들이 정렬되어 있는 Set이며 해당 인터페이스를 구현한 클래스로는 Treeset이 있다
  • Treeset 예제는 아래와 같음
import java.util.SortedSet;
import java.util.TreeSet;
public class Main {
  public static void main(String[] args) {

    SortedSet<String> sortedNames = new TreeSet<>();
    sortedNames.add("2");
    sortedNames.add("5");
    sortedNames.add("3");
    sortedNames.add("1");
    sortedNames.add("4");

    System.out.println(sortedNames);
  }

}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}