美文网首页
ArrayList get方法实现源码解读

ArrayList get方法实现源码解读

作者: 粽十三丶 | 来源:发表于2021-03-30 18:07 被阅读0次

ArrayList get方法实现

1.先看源码

public E get(int index) {

//检查请求的索引位

        rangeCheck(index);

        return elementData(index);

    }

2.rangeCheck方法实现

private void rangeCheck(int index) {

//如果长度大于等于元素的长度,直接抛出索引越界异常

        if (index >= size)

            throw new IndexOutOfBoundsException(outOfBoundsMsg(index));

    }

3.直接return ,完了。哈哈哈哈哈啊哈哈哈哈哈哈哈哈哈

皮一下很开心

相关文章

网友评论

      本文标题:ArrayList get方法实现源码解读

      本文链接:https://www.haomeiwen.com/subject/jrvghltx.html