Advertisement
Guest User

Untitled

a guest
Dec 14th, 2010
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.62 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3.  
  4. // comparable must be extended by T to use Collections.min
  5. class ListNum <T extends Number & Comparable<T>>
  6. {
  7.   private ArrayList<T> al_;
  8.  
  9.   public ListNum() {
  10.     al_ = new ArrayList<T>();
  11.   }
  12.  
  13.   public boolean add(T object) {
  14.     return al_.add(object);
  15.   }
  16.  
  17.   public T min() {
  18.     return Collections.min(al_);
  19.   }
  20. }
  21.  
  22. public class ListTest
  23. {
  24.   static public void main(String args[]) {
  25.     ListNum<Double> list = new ListNum<Double>();
  26.     list.add(3.0);
  27.     list.add(2.0);
  28.     list.add(4.0);
  29.    
  30.     System.out.println(list.min());
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement