博客
关于我
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/

你可能感兴趣的文章
nginx+uwsgi+django
查看>>
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Vue中向js中传递参数并在js中定义对象并转换参数
查看>>
Nginx、HAProxy、LVS
查看>>
nginx一些重要配置说明
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx与Tengine安装和使用以及配置健康节点检测
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
Nginx中使用keepalive实现保持上游长连接实现提高吞吐量示例与测试
查看>>