首页 > 解决方案 > Java数组列表实现中Object[] es = elementData的目的是什么

问题描述

在 Array List 实现中,我们有这段代码。对象数组的目的是什么?为什么使用它,为什么不对 elementData 本身执行操作?

int indexOfRange(Object o, int start, int end) {
        Object[] es = elementData;
        if (o == null) {
            for (int i = start; i < end; i++) {
                if (es[i] == null) {
                    return i;
                }
            }
        } else {
            for (int i = start; i < end; i++) {
                if (o.equals(es[i])) {
                    return i;
                }
            }
        }
        return -1;
    }

标签: java

解决方案


推荐阅读