Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 14th, 2010  |  syntax: Java 5  |  size: 0.62 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }