1
데이터가있는 기존 HashSet을 사용하여 TreeSet을 만들려고합니다. 그러나 외부 Comparator를 전달할 수있는 오버로드 된 메서드를 찾을 수 없습니까?데이터가 포함 된 기존 HashSet을 사용하여 TreeSet을 만드는 방법은 무엇입니까?
TreeSet을 생성하는 동안 외부 비교기를 사용할 수 있습니까?
public static void main(String[] args) {
Set<Bus> m = new HashSet<>();
Bus b1 = new Bus(1, "bhl", "udr");
Bus b2 = new Bus(2, "ahmd", "mum");
m.add(b1);
m.add(b2);
//Below will create treeset using default comparable logic.
Set<Bus> treeObject = new TreeSet<>(m);
// There is no overloaded constructor like this.
Set<Bus> treeObject = new TreeSet<>(m, new BusComparator());
어떻게 처리 할 수 있습니까?
:'공공 TreeSet의 (컬렉션 extends E> C) {이(); addAll (c); }' – Andreas