SHARE
TWEET

Untitled

a guest Dec 14th, 2010 30 Never
  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. }
RAW Paste Data
Top