2014-10-18 2 views
1

(학습 과제 - 막혔습니다.) Vector 요소를 항상 확장하는 클래스 (SortedVector)를 만들어야합니다. addElement 메서드를 오버로드하는 방법을 알아낼 수 없습니다. Collections.sort을 사용해야합니다.Vector에서 SortedVector

public class SortedVector extends Vector { 
    public void addElement(Object o){ 
     super.add(o); 
     Collections.sort(); //what do I do here? 
    } 
} 
+0

힌트 : 정렬 할 개체가? – SJuan76

답변

0

당신은 현재 컬렉션 정렬 할 - 그래서 그냥 통과를 thisCollections.sort에 :

public class SortedVector extends Vector { 
    public void addElement(Object o){ 
     super.add(o); 
     Collections.sort(this); // Note the usage of this 
    } 
} 
+0

감사합니다. 지금은 분명합니다. –