Java SortedSet create from List via TreeSet

Description

Java SortedSet create from List via TreeSet

import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
  public static void main(String[] args) {
    List<Integer> data = new LinkedList<>();

    data.add(30);//w w  w .  ja  va2s.c  o  m
    data.add(40);
    data.add(50);
    data.add(10);
    data.add(20);

    SortedSet<Integer> keys = new TreeSet<Integer>(data);
    
    for (Integer key : keys) {
      System.out.println(key);
    }
  }
}



PreviousNext

Related