//查找集合指定元素,返回元素所在索引 //若元素不存在,n表示该元素最有可能存在的位置索引 int index1 = Collections.binarySearch(list2, "Thursday"); int index2 = Collections.binarySearch(list2, "TTTTTT"); System.out.println(index1); int n = -index2 - 1;
//查找子串在集合中首次出现的位置 List<String> subList = Arrays.asList("Friday,Saturday".split(",")); int index3 = Collections.indexOfSubList(list2, subList); System.out.println(index3); int index4 = Collections.lastIndexOfSubList(list2, subList); System.out.println(index4);
//替换集合中指定的元素,若元素存在返回true,否则返回false boolean flag = Collections.replaceAll(list2, "Sunday", "tttttt"); System.out.println(flag); System.out.println(list2);