摘要: Vector Stack Hashtable java.util.concurrent 包下所有的集合类 ArrayBlockingQueue、ConcurrentHashMap、ConcurrentLinkedQueue、ConcurrentLinkedDeque... 来一道刷了进BAT的面试题 阅读全文
posted @ 2019-11-20 21:49 ConstXiong 阅读(2729) 评论(0) 推荐(0) 编辑
摘要: Queue 中 remove() 和 poll() 都是用来从队列头部删除一个元素。 在队列元素为空的情况下,remove() 方法会抛出NoSuchElementException异常,poll() 方法只会返回 null 。 JDK1.8 中的源码解释 /** * Retrieves and r 阅读全文
posted @ 2019-11-20 21:48 ConstXiong 阅读(2649) 评论(0) 推荐(0) 编辑
摘要: Queue 中 element() 和 peek() 都是用来返回队列的头元素,不删除。 在队列元素为空的情况下,element() 方法会抛出NoSuchElementException异常,peek() 方法只会返回 null。 JDK1.8 中源码解释 /** * Retrieves, but 阅读全文
posted @ 2019-11-20 21:48 ConstXiong 阅读(1907) 评论(0) 推荐(0) 编辑
摘要: Queue 中 add() 和 offer() 都是用来向队列添加一个元素。 在容量已满的情况下,add() 方法会抛出IllegalStateException异常,offer() 方法只会返回 false 。 JDK1.8 源码中的解释 /** * Inserts the specified e 阅读全文
posted @ 2019-11-20 10:40 ConstXiong 阅读(2262) 评论(0) 推荐(0) 编辑
摘要: 数组转 List ,使用 JDK 中 java.util.Arrays 工具类的 asList 方法 public static void testArray2List() { String[] strs = new String[] {"aaa", "bbb", "ccc"}; List<Stri 阅读全文
posted @ 2019-11-20 10:39 ConstXiong 阅读(5829) 评论(0) 推荐(0) 编辑
摘要: Array 即数组,声明方式可以如下: int[] array = new int[3]; int array [] = new int[3]; int[] array = {1, 2, 3}; int[] array = new int[]{1, 2, 3}; 定义一个 Array 时,必须指定数 阅读全文
posted @ 2019-11-20 10:38 ConstXiong 阅读(4366) 评论(0) 推荐(0) 编辑
摘要: ArrayList基于动态数组实现的非线程安全的集合;LinkedList基于链表实现的非线程安全的集合。 对于随机index访问的get和set方法,一般ArrayList的速度要优于LinkedList。因为ArrayList直接通过数组下标直接找到元素;LinkedList要移动指针遍历每个元 阅读全文
posted @ 2019-11-20 10:37 ConstXiong 阅读(1222) 评论(0) 推荐(0) 编辑
摘要: HashMap基于散列桶(数组和链表)实现;TreeMap基于红黑树实现。 HashMap不支持排序;TreeMap默认是按照Key值升序排序的,可指定排序的比较器,主要用于存入元素时对元素进行自动排序。 HashMap大多数情况下有更好的性能,尤其是读数据。在没有排序要求的情况下,使用HashMa 阅读全文
posted @ 2019-11-20 10:35 ConstXiong 阅读(1123) 评论(0) 推荐(0) 编辑