Java tutorial
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Stack; public class Main { public static <E> E peekOrNull(final Stack<? extends E> stack) { return !isEmpty(stack) ? stack.peek() : null; } public static boolean isEmpty(final Collection<?> collection) { return (collection == null) || collection.isEmpty(); } }