ArrayList的sublist注意
1 void testArrayList(){ 2 String []appname ={"联系人","相机","电话","收音机","手电筒","更多"}; 3 String s_appname = null; 4 List<Map<String, Object>> gv_applist = new ArrayList<Map<String,Object>>(); 5 for(int i=0; i<appname.length;i++) { 6 7 s_appname = appname[i]; 8 Map<String, Object> map = new HashMap<String, Object>(); 9 map.put("appname", s_appname); 10 gv_applist.add(map); 11 } 12 13 14 List<Map<String, Object>> templist1 = new ArrayList<Map<String, Object>>(); 15 templist1 = gv_applist.subList(0, 4); 16 System.out.println(templist1.size());//输出4 17 // gv_applist.remove(2); 18 templist1.size();//报错 java.util.ConcurrentModificationException 19 20 21 List<Map<String, Object>> templist2 = new ArrayList<Map<String, Object>>(gv_applist.subList(0, 4)); 22 System.out.println(templist2.size());//输出4 23 gv_applist.remove(2); 24 System.out.println(templist2.size());//输出4,这种方式子链表不受母链表影响,母链表可以任意操作 25 26 templist2.remove(2); 27 System.out.println(templist2.size());//输出3 28 29 30 }