* @author hanchao 2018/2/23 22:33**/public class ArraysAndCollectionsUtils {private static final Logger LOGGER = Logger.getLogger(ArraysAndCollectionsUtils.class);public static void main(String[] args) {LOGGER.info("Arrays工具类中的泛型示例:public static List asList(T... a) {}");List extends Number> numberList = Arrays.asList(1,2D,3L,4.0F);numberList.forEach(LOGGER::info);System.out.println();LOGGER.info("Collections工具类中的泛型示例:二分查找public static " +" int binarySearch(List extends Comparable super T>> list, T key) {}");List
运行结果:
2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:18 - Arrays工具类中的泛型示例:public static List asList(T... a) {}2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 12018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 2.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 32018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 4.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:23 - Collections工具类中的泛型示例:二分查找public static int binarySearch(List extends Comparable super T>> list, T key) {}2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:30 - 二分查找:22018-02-23 23:00:02 INFOArraysAndCollectionsUtils:33 - Collections工具类中的泛型示例:排序public static > void sort(List list) {}2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:35 - 第一次打印:2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 2.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 1.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 3.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:37 - 排序2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:39 - 第二次打印:2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 1.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 2.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:3880 - 3.02018-02-23 23:00:02 INFOArraysAndCollectionsUtils:43 - Collections工具类中的泛型示例:排序public static void copy(List super T> dest, List extends T> src) {}2018-02-23 23:00:02 INFOArraysAndCollectionsUtils:47 - [A, B, C, d]
5.总结
由于这些集合类和工具类提供的静态方法都比较常见 , 上面没有过多描述 。
其实在Java集合框架中 , 还有更多的泛型类和泛型方法 , 这里就不一一例句了 。
- java 备忘录方法求解,Java备忘录模式
- 业余学java赚钱,不吃透都对不起自己
- Java-透析 -> 查找算法
- Java 大学B组 第十届蓝桥杯 2019年国赛真题
- Java 大学C组 第十届蓝桥杯 2019年国赛真题
- java高校信息管理系统,java高校机房预约管理系统
- java设计模式之 代理模式
- [附源码]Java计算机毕业设计SSM翻转课堂微视频管理系统
- java null
- Object javascript基础--对象封装