标签:ted 比较 有序 stat .com extend demo ace cti
public static <T extends Comparable<? super T>> void sort(List<T> list)
public static <T> void sort(List<T> list,Comparator<? super T> c)
package java17; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * 2017/10/10 * 说明: */ public class CollectionsDemo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("abcde"); list.add("cdb"); list.add("aaa"); list.add("zzz"); list.add("cdb"); System.out.println("排序前:"+list); Collections.sort(list); System.out.println("排序后:"+list); } }
public static <T> int binarySearch(List<? extends Comparable<? super T>> list, T key)
public static <T> int binarySearch(List<? extends T> list, T key, Comparator<? super T> c)
package java17; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * 2017/10/10 * 说明: */ public class CollectionsDemo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("abcde"); list.add("cdb"); list.add("aaa"); list.add("zzz"); list.add("cdb"); Collections.sort(list); int index = Collections.binarySearch(list,"aaa"); System.out.println(index); } }
public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp)
public static <T extends Object & Comparable<? super T>> T min(Collection<? extends T> coll)
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp)
package java17; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * 2017/10/10 * 说明: */ public class CollectionsDemo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("abcde"); list.add("cdb"); list.add("aaa"); list.add("zzz"); list.add("cdb"); System.out.println("最大值:"+Collections.max(list)); System.out.println("最小值:"+Collections.min(list)); } }
public static <T> Comparator<T> reverseOrder()
public static <T> Comparator<T> reverseOrder(Comparator<T> cmp)
package java17; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.TreeSet; /** * 2017/10/10 * 说明: */ public class CollectionsDemo { public static void main(String[] args) { TreeSet<String> set = new TreeSet<>(); set.add("abcde"); set.add("cdb"); set.add("aaa"); set.add("zzz"); System.out.println(set); } }
package java17; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.TreeSet; /** * 2017/10/10 * 说明: */ public class CollectionsDemo { public static void main(String[] args) { TreeSet<String> set = new TreeSet<>(Collections.reverseOrder()); set.add("abcde"); set.add("cdb"); set.add("aaa"); set.add("zzz"); System.out.println(set); } }
public static <T> boolean replaceAll(List<T> list, T oldVal, T newVal)
package java17; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.TreeSet; /** * 2017/10/10 * 说明: */ public class CollectionsDemo { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("abcde"); list.add("cdb"); list.add("aaa"); list.add("zzz"); Collections.replaceAll(list,"cdb","bdc"); System.out.println(list); } }
public static <T> Collection<T> synchronizedCollection(Collection<T> c)
public static <T> List<T> synchronizedList(List<T> list)
public static <K,V> Map<K,V> synchronizedMap(Map<K,V> m)
public static <T> Set<T> synchronizedSet(Set<T> s)
public static <K,V> SortedMap<K,V> synchronizedSortedMap(SortedMap<K,V> m)
public static <T> SortedSet<T> synchronizedSortedSet(SortedSet<T> s)
public static String toString(int[] a)
package java17; import java.util.Arrays; /** * 2017/10/11 * 说明: */ public class ArraysDemo { public static void main(String[] args) { int[] arr = new int[]{1,5,8,3,2}; System.out.println("调用Arrays方法之前:"+arr); System.out.println("调用Arrays方法之后:"+Arrays.toString(arr)); } }
public static <T> List<T> asList(T... a)
package java17; import java.util.Arrays; import java.util.List; /** * 2017/10/11 * 说明: */ public class ArraysDemo { public static void main(String[] args) { String[] arr = new String[]{"abc","cdg","efg","sfg"}; List<String> list = Arrays.asList(arr); System.out.println(list.contains("sfg")); } }
package java17; import javax.net.ssl.SSLContext; import java.util.Arrays; import java.util.List; /** * 2017/10/11 * 说明: */ public class ArraysDemo { public static void main(String[] args) { String[] arr = new String[]{"abc","cdg","efg","sfg"}; List<String> list = Arrays.asList(arr); list.add("aa"); System.out.println("list:"+list); } }
package java17; import javax.net.ssl.SSLContext; import java.util.Arrays; import java.util.List; /** * 2017/10/11 * 说明: */ public class ArraysDemo { public static void main(String[] args) { int[] arr = new int[]{1,3,4,5}; List<int[]> list = Arrays.asList(arr); System.out.println("list:"+list.toString()); } }
标签:ted 比较 有序 stat .com extend demo ace cti
原文地址:http://www.cnblogs.com/xuweiweiwoaini/p/7648616.html