标签:
List方法subList(fromIndex,toIndex)测试案例
public class TestSubList { public static void main(String[] args) { List<String> list = new ArrayList<String>(); for (int i = 0; i < 10; i++) { list.add(i+""); } /** * subList(fromIndex,toIndex) * 对指定的集合从下标formIndex取到下标toIndex,[fromIndex,toIndex), * 对于指定size=10的集合,下标有0-9,共10个下标, */ List<String> sublist1 = list.subList(0, 5); // [0, 1, 2, 3, 4] List<String> sublist2 = list.subList(5, 9); // [5, 6, 7, 8] List<String> sublist3 = list.subList(5, 10); // [5, 6, 7, 8, 9] List<String> sublist4 = list.subList(10, 10); // [] List<String> sublist5 = list.subList(10, 11); // IndexOutOfBoundsException: toIndex = 11 // System. out.println(sublist1); System. out.println(sublist2); System. out.println(sublist3); System. out.println(sublist4); System. out.println(sublist5); } }
List方法subList(fromIndex,toIndex)测试
标签:
原文地址:http://my.oschina.net/xiaoxiangdaizi/blog/491241