AbstractList.equals(Object o)
来源:互联网 发布:免费手机小号软件 编辑:程序博客网 时间:2024/06/06 03:27
做java2年多,没什么长进,在未来1年要研究一般JDK源码,每天记载一点:
AbstractList.equals(Object o)的实现源码写的实在是太简练、精辟了
public boolean equals(Object o) {if (o == this) return true;if (!(o instanceof List)) return false;ListIterator<E> e1 = listIterator();ListIterator e2 = ((List) o).listIterator();while(e1.hasNext() && e2.hasNext()) { E o1 = e1.next(); Object o2 = e2.next(); if (!(o1==null ? o2==null : o1.equals(o2)))return false;}return !(e1.hasNext() || e2.hasNext()); }
Iterrator实现源码
private class Itr implements Iterator<E> {/** * Index of element to be returned by subsequent call to next. */int cursor = 0;/** * Index of element returned by most recent call to next or * previous. Reset to -1 if this element is deleted by a call * to remove. */int lastRet = -1;/** * The modCount value that the iterator believes that the backing * List should have. If this expectation is violated, the iterator * has detected concurrent modification. */int expectedModCount = modCount;public boolean hasNext() { return cursor != size();}public E next() { checkForComodification(); try {E next = get(cursor);lastRet = cursor++;return next; } catch (IndexOutOfBoundsException e) {checkForComodification();throw new NoSuchElementException(); }}public void remove() {//验证当前迭代元素是否已经remove if (lastRet == -1)throw new IllegalStateException(); checkForComodification(); try { //remove当前迭代的元素AbstractList.this.remove(lastRet);//索引位置-1if (lastRet < cursor) cursor--;//修改移除元素标志lastRet = -1;//遍历时 集合添加修改标志?expectedModCount = modCount; } catch (IndexOutOfBoundsException e) {throw new ConcurrentModificationException(); }}final void checkForComodification() { if (modCount != expectedModCount)throw new ConcurrentModificationException();} }
0 0
- AbstractList.equals(Object o)
- AbstractList
- AbstractList
- Object.equals()
- 源码分析-java-AbstractList-subList、RandomAccess、equals和hashCode
- Object类的解释(equals,hashcode)
- Object类(二)equals方法
- Java中的Object-equals()方法
- "".equals(object)和object.equals("")问题
- Java Object equals() & hashCode()
- Object.Equals()的用法
- JAVA Object类-equals()
- Object类equals()
- 重载Object equals方法
- Java object equals hashcode
- Object 类中的equals
- Java Object equals方法
- Object的equals方法
- hdu 1829 A Bug's Life
- hdu1002
- 字符设备驱动之led灯的控制实验
- C++编程问题--glibc detected *** ./a.out: munmap_chunk(): invalid pointer: xxxxxx
- POJ 2309 BST 二叉树性质 位运算
- AbstractList.equals(Object o)
- [C\C++基础知识] main函数的参数argc和argv
- action里面获取session以及获取设置session的属性
- C++篇 特破private
- hdu 1503 Advanced Fruits(最长公共子序列变形)
- 题目1214:丑数
- 从Linux内核代码中学习获得结构体成员偏移量的方法
- int main(int argc,char* argv[])详解
- 【struts】Unable to load configuration 相关仔细查看报错信息