1.list截取指定部分
List sublist = new ArrayList();
sublist = new ArrayList(alist.subList(2, 4));
2.在指定位置更新内容
public ArrayList attrs = new ArrayList<>();//图层属性
attrs.set(position, "string");
3.判断Arraylis中是否有重复内容
public static void main(String[] args)
{
List list = new ArrayList();
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)的相互转化
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 hashMap = iMarkerService.getBaiduMarkerMap();
ArrayList markers = new ArrayList<>(hashMap.values());
6.转换成字符串 join
List userParms=new ArrayList();
String userSql = String.join(" AND ", userParms);
8.排序
Collections.sort(warnRes, new Comparator() {//按终保日期排序
public int compare(WarnRes warnRes0, WarnRes warnRes1) {
return warnRes1.getZbrq().compareTo(warnRes0.getZbrq());
}
});