Java tutorial
//package com.java2s; import java.util.Collections; import java.util.List; public class Main { public static <O> List<O> safeSubList(List<O> l, int size) { try { if (l.size() < size) { return l; } return l.subList(0, size); } catch (Throwable ex) { return l; } } public static <O> List<O> safeSubList(List<O> l, int offset, int count) { if (l == null) { return null; } if (offset >= l.size()) return Collections.emptyList(); if (count == 0) count = l.size(); return l.subList(offset, Math.min(offset + count, l.size())); } }