博客
关于我
00020.04 Vector的源码跟踪
阅读量:613 次
发布时间:2019-03-12

本文共 649 字,大约阅读时间需要 2 分钟。

系列文章目录

文章目录

前言

需要注意会进行各种各样的跳转

一、Vector的源码跟踪

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
同样add方法也可以去跟踪,跟踪后发现
在这里插入图片描述

Vector 无参构造 就做了

(1)new Vector () 初始化长度为10的数组,默认增量是0
(2)add(E e) 默认扩容为原来的2倍,如果你手动指定了capacityIncrement的值,那么可以按照你指定增量进行扩容。
(3)add(index,e):
①考虑扩容
②移动元素
③添加元素
④元素个数增加
(4)remove(index):
在这里插入图片描述
①计算要移动元素的个数
②如果需要移动,调用System.arraycopy方法进行移动
③elementData[–elementCount] = null;
(5)remove(Object obj)
①查找obj的下标
②如果不是-1就调用remove(index)进行删除
(6)indexOf(Object obj)
对obj分情况讨论:(1)是null(2)不是null

二、代码

public class TestVector {   	@Test	public void test1(){   		Vector v = new Vector();				v.add("1");		v.add(0, "2");//[0]				v.remove(1);				v.remove("1");				int index = v.indexOf("1");	}}

总结:

可以向源代码去学习功能的实现

转载地址:http://wmgxz.baihongyu.com/

你可能感兴趣的文章
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>