// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class FindMaxDemo {
    private List<Data> lst = new ArrayList<Data>();
    public void addTestData() {
        lst.add(new Data(3));
        lst.add(new Data(7));
        lst.add(new Data(1));
        lst.add(new Data(6));
        lst.add(new Data(2));
    }
    public Data findMax1() {
        if(lst.size() <= 0) return null;
        int maxix = 0;
        int maxval = lst.get(maxix).getValue();
        for(int i = 1; i < lst.size(); i++) {
            if(maxval < lst.get(i).getValue()) {
                maxix = i;
                maxval = lst.get(maxix).getValue();
            }
        }
        return lst.get(maxix);
    }
    public Data findMax2() {
        if(lst.size() <= 0) return null;
        Data res = lst.get(0);
        for(int i = 1; i < lst.size(); i++) {
            if(res.getValue() < lst.get(i).getValue()) {
                res = lst.get(i);
            }
        }
        return res;
    }
    public Data findMax3() {
        return Collections.max(lst, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d1.getValue() - d2.getValue();
            }
        });
    }
    public static void main(String[] args) {
        FindMaxDemo demo = new FindMaxDemo();
        demo.addTestData();
        System.out.println(demo.findMax1().getValue());
        System.out.println(demo.findMax2().getValue());
        System.out.println(demo.findMax3().getValue());
    }
}

class Data {
    private int value;
    public Data(int value) {
        this.value = value;
    }
    public int getValue() {
        return value;
    }
}
