Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> List<T> sub(List<T> list, int start, int end) { if (list == null || list.isEmpty()) { return new ArrayList<>(); } if (start < 0) { start = 0; } if (end < 0) { end = 0; } if (start > end) { int tmp = start; start = end; end = tmp; } final int size = list.size(); if (end > size) { if (start >= size) { return new ArrayList<>(); } end = size; } return list.subList(start, end); } public static <T> List<T> sub(Collection<T> list, int start, int end) { if (list == null || list.isEmpty()) { return new ArrayList<>(); } return sub(new ArrayList<T>(list), start, end); } public static <T> boolean isEmpty(T[] array) { return array == null || array.length == 0; } public static boolean isEmpty(Collection<?> collection) { return collection == null || collection.isEmpty(); } public static boolean isEmpty(Map<?, ?> map) { return map == null || map.isEmpty(); } }