SparseArray中的indexOfValue与ArrayList中indexOf的区别
来源:互联网 发布:只有程序员才懂的笑话 编辑:程序博客网 时间:2024/06/08 16:13
SparseArray:
/** * Returns an index for which {@link #valueAt} would return the * specified key, or a negative number if no keys map to the * specified value. * <p>Beware that this is a linear search, unlike lookups by key, * and that multiple keys can map to the same value and this will * find only one of them. * <p>Note also that unlike most collections' {@code indexOf} methods, * this method compares values using {@code ==} rather than {@code equals}. */ public int indexOfValue(E value) { if (mGarbage) { gc(); } for (int i = 0; i < mSize; i++) if (mValues[i] == value) return i; return -1; }
ArrayList:
@Override public int indexOf(Object object) { Object[] a = array; int s = size; if (object != null) { for (int i = 0; i < s; i++) { if (object.equals(a[i])) { return i; } } } else { for (int i = 0; i < s; i++) { if (a[i] == null) { return i; } } } return -1; }
SparseArray中的indexOfValue判断不是equals,如果SparseArray中的value为String类型时,indexOfValue(“xxx”)会返回-1。
0 0
- SparseArray中的indexOfValue与ArrayList中indexOf的区别
- 安卓SparseArray的indexOfValue方法遇到的坑
- C#中的Contains与IndexOf的区别
- C#中的Contains与IndexOf的区别
- Java中List集合中contains()与indexOf()的区别
- indexOf与search的区别
- indexOf与includes的区别
- 转:c#中indexof与substring的区别
- Java字符串String中contains与indexOf的区别
- ArrayList的indexOf用法
- 关于java中indexOf方法在ArrayList集合中的使用
- 关于arraylist类中indexof方法与lastindexof方法的使用
- java中的ArrayList与LinkedList的区别
- Java中的Vector与ArrayList的区别
- C#中Array与ArrayList的区别
- C#中Array与ArrayList的区别
- java中List与ArrayList的区别?
- JAVA中Array与ArrayList的区别
- 《挑战程序设计竞赛》3.3.2 数据结构-线段树和平方分割 POJ2991 3264 2104 3468 3368 3470 1201 UVA11990(4)
- 数据库和实例的文件类型
- iOS 信鸽SDK完整接入
- android更新代理!!!!
- 秒杀多线程第十二篇 多线程同步内功心法——PV操作上
- SparseArray中的indexOfValue与ArrayList中indexOf的区别
- flare 3D之加载模型资源见解
- rinetd端口转发
- C语言学习笔记1:static
- 《挑战程序设计竞赛》3.4.1 动态规划-状态压缩DP POJ3311 2686 2411 2441 3254 2836 1795 3411(2)
- iOS网络编程:五、Post代理异步
- open()方法的大小问题
- Objective-C
- 秒杀多线程第十四篇 读者写者问题继 读写锁SRWLock