
java源码
Sun_hxx
这个作者很懒,什么都没留下…
展开
-
java源码之HashMap的get
java源码之HashMap的get今天面试了一天本来不想写了,但想想自己立下的flag,还是继续写。今天面试的时候被面试官询问hashMap的get方法底层源码是什么样子的,没看过,遂晚上回来看看。final Node<K,V> getNode(int hash, Object key) { Node<K,V>[] tab; Node<K,V> first, e; int n; K k; if ((tab = table) != nu原创 2021-03-24 23:51:15 · 127 阅读 · 0 评论 -
LinkedList的add源码(2)
LinkedList的add源码(2)上一篇文章我们看了不指定下标的情况下java对LinkedList添加元素是如何处理的,这次我们就看下在指定下标的情况下又是如何实现元素的添加的呢?public static void main(String[] args) { LinkedList<Integer> list = new LinkedList<>(); list.add(1); list.add(2); list.add(3); li原创 2021-03-20 14:28:38 · 111 阅读 · 0 评论 -
LinkedList的add源码(1)
LinkedList的add源码public static void main(String[] args) { LinkedList<Integer> list = new LinkedList<>(); list.add(1); }点击查看add方法public boolean add(E e) { linkLast(e); return true; }再查看linkLast方法/**原创 2021-03-20 09:51:32 · 153 阅读 · 0 评论 -
String的contains方法源码
String的contains方法源码public static void main(String[] args) { String str = "123"; System.out.println(str.contains("12"));}咱们点进去看一下这个contains方法public boolean contains(CharSequence s) { return indexOf(s.toString()) > -1;}我们发现传进去的是一个CharS原创 2021-03-19 23:53:12 · 740 阅读 · 0 评论 -
String的subString方法源码
String的subString方法源码public String substring(int beginIndex, int endIndex) { if (beginIndex < 0) { throw new StringIndexOutOfBoundsException(beginIndex); } if (endIndex > value.length) { throw new StringIndexOutOfBoundsExc原创 2021-03-19 10:53:05 · 395 阅读 · 0 评论 -
ArrayList集合remove源码
ArrayList集合remove源码remove的源码比较简单,但是有public E remove(int index) { rangeCheck(index); modCount++; E oldValue = elementData(index); int numMoved = size - index - 1; if (numMoved > 0) System.arraycopy(elementData, index+1, el原创 2021-03-18 17:35:32 · 351 阅读 · 0 评论 -
ArrayList的创建源码
ArrayList的创建public class ListTest { public static void main(String[] args) { List<Integer> list = new ArrayList<>(); list.add(1); }}点进去看一下构造方法/*** Constructs an empty list with an initial capacity of ten.*/public原创 2021-03-18 15:47:24 · 278 阅读 · 0 评论 -
ArrayList集合add源码
ArrayList元素的添加public class ListTest { public static void main(String[] args) { List<Integer> list = new ArrayList<>(); list.add(1); }}public boolean add(E e) { ensureCapacityInternal(size + 1); // Increments mod原创 2021-03-18 15:47:14 · 243 阅读 · 1 评论 -
集合删除元素出现ConcurrentModificationException异常
集合删除元素出现ConcurrentModificationException异常在操作集合遍历删除集合中某个元素时,就可能会出现这个异常,那么为什么会产生异常呢?Exception in thread "main" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) at java.util.ArrayList$Itr.next原创 2021-03-18 10:45:25 · 385 阅读 · 1 评论