1.list截取指定部分java
List sublist = new ArrayList(); sublist = new ArrayList<String>(alist.subList(2, 4));
2.在指定位置更新內容python
public ArrayList<String> attrs = new ArrayList<>();//圖層屬性 attrs.set(position, "string");
3.判斷Arraylis中是否有重複內容數組
public static void main(String[] args) { List<String> list = new ArrayList<String>(); list.add("aa"); list.add("bb"); list.add("cc"); list.add("dd"); list.add("bb"); list.add("ee"); list.add("dd"); list.add("ff"); String temp = ""; for (int i = 0; i < list.size() - 1; i++) { temp = list.get(i); for (int j = i + 1; j < list.size(); j++) { if (temp.equals(list.get(j))) { System.out.println("第" + (i + 1) + "個跟第" + (j + 1) + "個重複,值是:" + temp); } } } }
4.java中集合(list)與數組(Array)的相互轉化code
1) 數組轉化爲集合
數組能夠轉化爲List,可是除了顯示功能之外,其餘功能不能使用,由於經過轉換獲得的list不知到是什麼類型的,能夠經過集合的構造方法賦值,來使用其餘的功能:
String[] names ={"劉備","曹操","諸葛亮"}; List list1 = Arrays.asList(names); list1 = new ArrayList(list1);
2) 集合轉化爲數組
Object[] ary1 = list3.toArray(new String[list3.size()]); //System.out.println(Arrays.toString(ary1));
5.Hashmap轉化成arraylist排序
HashMap<String, Marker> hashMap = iMarkerService.getBaiduMarkerMap(); ArrayList<Marker> markers = new ArrayList<>(hashMap.values());
6.轉換成字符串 join字符串
List<String> userParms=new ArrayList(); String userSql = String.join(" AND ", userParms);
8.排序get
Collections.sort(warnRes, new Comparator<WarnRes>() {//按終保日期排序 public int compare(WarnRes warnRes0, WarnRes warnRes1) { return warnRes1.getZbrq().compareTo(warnRes0.getZbrq()); } });