![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java Conllection
折挺
干好一件件小事!
展开
-
快速失败(fail-fast)和安全失败(fail-safe)的区别是什么?
一:快速失败(fail—fast) 在用迭代器遍历一个集合对象时,如果遍历过程导致集合中元素个数变化(例如: add、remove、clear),则会抛出ConcurrentModificationException。 原理 : 迭代器在遍历时直接访问集合中的内容,并且在遍历过程中使用一个 modCount 变量。集合在被遍历期间如果元素数量发生变化,就会改变modCount的值。每当迭代器...转载 2018-07-03 07:55:32 · 7662 阅读 · 2 评论 -
Removing all Nulls from a List in Java
注意移除null元素是修改List本身还是,生成新的List没有null元素. package com.sheting.basic.collection.list; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import j...原创 2018-07-21 11:59:00 · 3450 阅读 · 0 评论 -
Converting between an Array and a List in Java
package com.sheting.basic.collection.list; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.commons.collections4.CollectionUtils; import com.google.comm...原创 2018-07-21 12:25:20 · 3447 阅读 · 0 评论 -
Converting Between an Array and a Set in Java
package com.sheting.basic.collection.list; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; import org.apache.commons.collections4.CollectionUti...原创 2018-07-21 16:47:40 · 3336 阅读 · 0 评论 -
Converting between a List and a Set in Java
package com.sheting.basic.collection.list; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import org.apache.commons.colle...原创 2018-07-21 16:56:51 · 3462 阅读 · 0 评论 -
Convert a Map to an Array, List or Set in Java
package com.sheting.basic.collection.list; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; im...原创 2018-07-21 17:11:11 · 3410 阅读 · 0 评论 -
JDK1.8 ArrayList扩容分析
ArrayList可以实现容量的自适应的增加(As elements are added to an ArrayList, its capacity grows automatically)。通过JDK1.8中ArrayList的源码来分析: ArrayList的相关定义 ArrayList底层采用Object类型的数组实现。 首先,定义默认初始容量,为10 private st...原创 2018-07-27 06:35:33 · 1184 阅读 · 1 评论 -
Collections.sort()
package com.sheting.sort.demo1; /** * @Author SheTing * @Time 2018/3/23 10:15 */ public class Emp implements Comparable<Emp>{ private int empno; private String ename; public in...原创 2018-07-27 06:36:49 · 1165 阅读 · 0 评论 -
Removing all duplicates from a List in Java
Remove duplicates from a List using plain Java package com.sheting.basic.collection.list; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; ...原创 2018-07-21 08:21:23 · 3401 阅读 · 0 评论 -
Initialization of an ArrayList in one line example
This tutorials demonstrates how to initialize a list or arraylist in one line in different ways. The traditional way to create and initialize anArrayList is: List<String> planets = new ArrayLi...原创 2018-07-06 07:50:19 · 3391 阅读 · 0 评论 -
Sorted Set Example – Ascending or Descending by comparator
Sorted Set Ascending order By TreeMap Example package com.sheting.basic.collection.sorted; import java.util.HashSet; import java.util.Set; import java.util.TreeSet; public class SetSimpleSorting ...原创 2018-07-06 07:40:11 · 3470 阅读 · 0 评论 -
What are Collection related features in Java 8?
Java 8 has brought major changes in the Collection API. Some of the changes are: Java Stream API for collection classes for supporting sequential as well as parallel processing default Stream...转载 2018-07-04 07:32:49 · 3344 阅读 · 0 评论 -
Different ways to Iterate over an ArrayList in Java
package com.sheting.basic.collection.iterate; import java.util.Arrays; import java.util.Iterator; import java.util.List; public class ListIterateProgram { public static void main(String... args...原创 2018-07-06 07:03:50 · 3432 阅读 · 0 评论 -
Different Ways to Iterate over a Set in Java
package com.sheting.basic.collection.iterate; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class SetIterateProgram { public static void main(String... args) ...原创 2018-07-06 07:06:46 · 3366 阅读 · 0 评论 -
Different Ways to Iterate over a Map in Java
package com.sheting.basic.collection.iterate; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; public class MapIterateProgram { public stat...原创 2018-07-06 07:10:57 · 3408 阅读 · 0 评论 -
Sorted List Example – Simple Reverse and Comparable Sort
Simple Sorted List Example package com.sheting.basic.collection.sorted; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class SimpleSorting { public st...原创 2018-07-06 07:19:39 · 3342 阅读 · 0 评论 -
Sorted Map Example – By Value or By Key or By Comparator
Sorted Map By Key Example package com.sheting.basic.collection.sorted; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class SortByKey { ...原创 2018-07-06 07:36:15 · 3461 阅读 · 0 评论 -
什么是HashMap?
众所周知,HashMap是一个用于存储Key-Value键值对的集合,每一个键值对也叫做Entry。这些个键值对(Entry)分散存储在一个数组当中,这个数组就是HashMap的主干。 HashMap数组每一个元素的初始值都是Null。 对于HashMap,我们最常使用的是两个方法:Get 和 Put。 1.Put方法的原理 调用Put方法的时候发生了什么呢? 比如调用 hashMa...原创 2018-07-27 07:15:27 · 3205 阅读 · 0 评论