java - SortedVector from Vector -
java - SortedVector from Vector -
(learning task - got stuck) need create class (sortedvector
) extends vector
sorting elements. can't figure out how overload addelement
method. must utilize collections.sort
.
public class sortedvector extends vector { public void addelement(object o){ super.add(o); collections.sort(); //what do here? } }
you want sort current collection - pass this
collections.sort
:
public class sortedvector extends vector { public void addelement(object o){ super.add(o); collections.sort(this); // note usage of } }
java inheritance vector overloading method-overloading
Comments
Post a Comment