Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- // comparable must be extended by T to use Collections.min
- class ListNum <T extends Number & Comparable<T>>
- {
- private ArrayList<T> al_;
- public ListNum() {
- al_ = new ArrayList<T>();
- }
- public boolean add(T object) {
- return al_.add(object);
- }
- public T min() {
- return Collections.min(al_);
- }
- }
- public class ListTest
- {
- static public void main(String args[]) {
- ListNum<Double> list = new ListNum<Double>();
- list.add(3.0);
- list.add(2.0);
- list.add(4.0);
- System.out.println(list.min());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement