8、SequenceInputStream的源码和Vector.class的一些函数说明(windows操作系统,JDK8)
<h4 id="一sequenceinputstream源码可以顺序读取多个输入stream的装饰器类">一、SequenceInputStream源码——可以顺序读取多个输入Stream的装饰器类</h4><p> SequenceInputStream.class 的UML关系图,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215215854830-1271542137.png"></p>
<p> SequenceInputStream.class的源码,如下所示:</p>
<pre><code>package java.io;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
public
class SequenceInputStream extends InputStream {
//顺序(序列化)装载多个被装饰输入Stream的集合,一般是Vector实例
Enumeration<? extends InputStream> e;
InputStream in;//顺序(序列化)装载多个被装饰输入Stream的集合中当前正在被SequenceInputStream 对象使用的被装饰的输入Stream
//构造函数,传入一个顺序(序列化)装载多个被装饰输入Stream的集合
public SequenceInputStream(Enumeration<? extends InputStream> e) {
this.e = e;
try {
nextStream();
} catch (IOException ex) {
// This should never happen
throw new Error("panic");
}
}
//构造函数,可以将2个被装饰的输入Stream放入到集合中
public SequenceInputStream(InputStream s1, InputStream s2) {
Vector<InputStream> v = new Vector<>(2);
v.addElement(s1);
v.addElement(s2);
e = v.elements();
try {
nextStream();
} catch (IOException ex) {
// This should never happen
throw new Error("panic");
}
}
//获取集合中下一个被装饰的输入Stream
final void nextStream() throws IOException {
if (in != null) {
in.close();//先关闭当前被装饰的输入Stream
}
if (e.hasMoreElements()) {//如果集合中还有被装饰的输入Stream
in = (InputStream) e.nextElement();//获取集合中下一个被装饰的输入Stream
if (in == null)
throw new NullPointerException();//如果集合中下一个被装饰的输入Stream为null,抛出一个NullPointerException
}
else in = null;//如果集合中没有了被装饰的输入Stream,将当前正在使用的被装饰的输入Stream置为null
}
//判断当前正在使用的被装饰的输入Stream是否还有可以读取的字节数据
public int available() throws IOException {
if (in == null) {
return 0; // no way to signal EOF from available()
}
return in.available();
}
//从SequenceInputStream 对象的集合(该集合放着多个被装饰的输入Stream)中读取1个字节
public int read() throws IOException {
while (in != null) {//如果in!=null,则说明当前这个SequenceInputStream 对象的集合中还有被装饰的输入Stream没有关闭
int c = in.read();//从当前正在使用的被装饰的被装饰输入Stream中读取1个字节
if (c != -1) {//c != -1说明从当前正在使用的被装饰输入Stream中读取到了字节
return c;//返回读取到的这个字节
}
nextStream();//如果c==-1说明当前正在使用的被装饰输入Stream中字节(byte)数据已经读完,获取SequenceInputStream 对象的集合中下一个被装饰的输入Stream
}
return -1;//如果SequenceInputStream 对象的集合中所有被装饰的输入Stream中的字节(byte)数据都已经读完,返回-1
}
//从SequenceInputStream 对象的集合(该集合放着多个被装饰的输入Stream)中读取len个字节,放入到byte[]数组b的[off,off+len)(左闭右开,不包括off+len)索引位置
public int read(byte b[], int off, int len) throws IOException {
if (in == null) {//如果in==null,则说明当前这个SequenceInputStream 对象的集合中所有被装饰的输入Stream都已经关闭
return -1;
} else if (b == null) {
throw new NullPointerException();//如果byte[]数组b==null,抛出一个NullPointerException
} else if (off < 0 || len < 0 || len > b.length - off) {//相当于off + len > b.length(源码中这样写代码的好处我没看出来)
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;//要从SequenceInputStream 对象的集合(该集合放着至少2个被装饰的输入Stream)中读取的len个字节==0时,返回0
}
do {
int n = in.read(b, off, len);//从当前正在使用的被装饰的输入Stream中读取len个字节,放入到byte[]数组b的[off,off+len)(左闭右开,不包括off+len)索引位置
if (n > 0) {
return n;//只要能从当前正在使用的被装饰的输入Stream中读取到字节,则返回读取的数量
}
nextStream();//此时n==-1,说明当前正在使用的被装饰的输入Stream中字节(byte)数据已经读完,获取SequenceInputStream 对象的集合中下一个被装饰的输入Stream
} while (in != null);//SequenceInputStream 对象的集合中下一个被装饰的输入Stream为null时,跳出循环,返回-1
return -1;
}
//顺序关闭SequenceInputStream 对象的集合中所有被装饰的输入Stream
public void close() throws IOException {
do {
nextStream();
} while (in != null);
}
}
</code></pre>
<h5 id="11sequenceinputstream的read函数和nextstream函数">1.1、SequenceInputStream的read()函数和nextStream()函数</h5>
<pre><code>package java.io;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
public
class SequenceInputStream extends InputStream {
...省略部分代码...
//顺序(序列化)存储多个被装饰的输入Stream的集合,一般是Vector实例
Enumeration<? extends InputStream> e;
InputStream in;//顺序(序列化)装载多个被装饰输入Stream的集合中当前正在被SequenceInputStream 对象使用的被装饰的输入Stream
//获取集合中下一个被装饰的输入Stream
final void nextStream() throws IOException {
if (in != null) {
in.close();//先关闭当前被装饰的输入Stream
}
if (e.hasMoreElements()) {//如果集合中还有被装饰的输入Stream
in = (InputStream) e.nextElement();//获取集合中下一个被装饰的输入Stream
if (in == null)
throw new NullPointerException();//如果集合中下一个被装饰的输入Stream为null,抛出一个NullPointerException
}
else in = null;//如果集合中没有了被装饰的输入Stream,将当前正在使用的被装饰的输入Stream置为null
}
//从SequenceInputStream 对象的集合(该集合放着多个被装饰的输入Stream)中读取1个字节
public int read() throws IOException {
while (in != null) {//如果in!=null,则说明当前这个SequenceInputStream 对象的集合中还有被装饰的输入Stream没有关闭
int c = in.read();//从当前正在使用的被装饰的被装饰输入Stream中读取1个字节
if (c != -1) {//c != -1说明从当前正在使用的被装饰输入Stream中读取到了字节
return c;//返回读取到的这个字节
}
nextStream();//如果c==-1说明当前正在使用的被装饰输入Stream中字节(byte)数据已经读完,获取SequenceInputStream 对象的集合中下一个被装饰的输入Stream
}
return -1;//如果SequenceInputStream 对象的集合中所有被装饰的输入Stream中的字节(byte)数据都已经读完,返回-1
}
...省略部分代码...
}
</code></pre>
<p>如果使用者用的是2个被装饰的输入Stream(此处为FileInputStream),构造的SequenceInputStream的对象,如下所示(伪代码):</p>
<pre><code>is1 = new FileInputStream("D:\\data1.txt");
is2 = new FileInputStream("D:\\data2.txt");
sequenceInputStream = new SequenceInputStream(is1, is2);
</code></pre>
<p>那么,SequenceInputStream对象中Vector集合的容量是2,如果此时执行SequenceInputStream.class::read()函数。</p>
<pre><code>//伪代码
int readByte = -1;
while ((readByte = sequenceInputStream.read()) != -1) {
System.out.print((char) readByte);
}
</code></pre>
<p>过程如下(假设2个被装饰的输入Stream(此处为FileInputStream)中的字节数据如下):<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220043218-349583290.png"></p>
<p>①、先执行第1个被装饰的输入Stream(也是Vector集合的第1个元素)的read()函数,直到该函数返回-1,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220100324-1139361487.png"><br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220109951-490306412.png"></p>
<p>②、关闭第1个被装饰的输入Stream(也是Vector集合的第1个元素),再执行第2个被装饰的输入Stream(也是Vector集合的第2个元素)的read()函数,直到该函数返回-1,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220126547-1754735555.png"><br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220135740-592304804.png"></p>
<h6 id="111使用举例">1.1.1、使用举例</h6>
<p> 下面这个例子就恰当的使用SequenceInputStream的read()函数;</p>
<ul>
<li>
<p>我的windows操作系统的D盘根目录下有2个txt文件,一个是data1.txt,另一个是data2.txt文件,这2个文件中总共有30个字节,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220203616-2107974847.png"><br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220213513-1764667319.png"></p>
</li>
<li>
<p>使用者可以用一个SequenceInputStream对象装饰2个被装饰的输入Stream(此处为FileInputStream),如下代码所示:</p>
</li>
</ul>
<pre><code>package com.chelong.StreamAndReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
public class SequenceInputStreamTest {
public static void main(String[] args) {
InputStream is1 = null;
InputStream is2 = null;
SequenceInputStream sequenceInputStream = null;
try {
is1 = new FileInputStream("D:\\data1.txt");
is2 = new FileInputStream("D:\\data2.txt");
sequenceInputStream = new SequenceInputStream(is1, is2);
int readByte = -1;
while ((readByte = sequenceInputStream.read()) != -1) {
System.out.print((char) readByte);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
//此处省略关闭所有的Stream的代码
}
}
}
</code></pre>
<p>程序运行结果,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220259069-1799250009.png"></p>
<h5 id="12sequenceinputstream的readbyte-b-int-off-int-len函数和nextstream函数">1.2、SequenceInputStream的read(byte b[], int off, int len)函数和nextStream()函数</h5>
<pre><code>package java.io;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Vector;
public
class SequenceInputStream extends InputStream {
...省略部分代码...
//顺序(序列化)装载多个被装饰输入Stream的集合,一般是Vector实例
Enumeration<? extends InputStream> e;
InputStream in;//顺序(序列化)装载多个被装饰输入Stream的集合中当前正在被SequenceInputStream 对象使用的被装饰的输入Stream
//获取集合中下一个被装饰的输入Stream
final void nextStream() throws IOException {
if (in != null) {
in.close();//先关闭当前被装饰的输入Stream
}
if (e.hasMoreElements()) {//如果集合中还有被装饰的输入Stream
in = (InputStream) e.nextElement();//获取集合中下一个被装饰的输入Stream
if (in == null)
throw new NullPointerException();//如果集合中下一个被装饰的输入Stream为null,抛出一个NullPointerException
}
else in = null;//如果集合中没有了被装饰的输入Stream,将当前正在使用的被装饰的输入Stream置为null
}
//从SequenceInputStream 对象的集合(该集合放着多个被装饰的输入Stream)中读取len个字节,放入到byte[]数组b的[off,off+len)(左闭右开,不包括off+len)索引位置
public int read(byte b[], int off, int len) throws IOException {
if (in == null) {//如果in==null,则说明当前这个SequenceInputStream 对象的集合中所有被装饰的输入Stream都已经关闭
return -1;
} else if (b == null) {
throw new NullPointerException();//如果byte[]数组b==null,抛出一个NullPointerException
} else if (off < 0 || len < 0 || len > b.length - off) {//相当于off + len > b.length(源码中这样写代码的好处我没看出来)
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;//要从SequenceInputStream 对象的集合(该集合放着至少2个被装饰的输入Stream)中读取的len个字节==0时,返回0
}
do {
int n = in.read(b, off, len);//从当前正在使用的被装饰的输入Stream中读取len个字节,放入到byte[]数组b的[off,off+len)(左闭右开,不包括off+len)索引位置
if (n > 0) {
return n;//只要能从当前正在使用的被装饰的输入Stream中读取到字节,则返回读取的数量
}
nextStream();//此时n==-1,说明当前正在使用的被装饰的输入Stream中字节(byte)数据已经读完,获取SequenceInputStream 对象的集合中下一个被装饰的输入Stream
} while (in != null);//SequenceInputStream 对象的集合中下一个被装饰的输入Stream为null时,跳出循环,返回-1
return -1;
}
...省略部分代码...
}
</code></pre>
<p>如果使用者用的是2个被装饰的输入Stream(此处为FileInputStream),构造的SequenceInputStream的对象,如下所示(伪代码):</p>
<pre><code>is1 = new FileInputStream("D:\\data1.txt");
is2 = new FileInputStream("D:\\data2.txt");
sequenceInputStream = new SequenceInputStream(is1, is2);
</code></pre>
<p>那么,SequenceInputStream对象中Vector集合的容量是2,并且假设这2个被装饰的输入Stream(此处为FileInputStream)中的字节数据如下:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220336936-422574713.png"></p>
<p>如果此时执行SequenceInputStream.class::read()函数。接下来使用SequenceInputStream对象读取字节数据到使用者创建的byte[]数组,如果使用者创建的字节数组byte[]的长度>=第1个被装饰的输入Stream中的所有字节个数,比如,使用者创建的byte[]数组的长度为12,如下所示(伪代码):</p>
<pre><code>int readByte = -1;
byte[] buff = new byte;
while ((readByte = sequenceInputStream.read(buff, 0, buff.length)) != -1) {
for (int i = 0; i < readByte; i++) {
System.out.print((char) buff);
}
}
</code></pre>
<p>整个执行过程如下:<br>
①、第1次进入read()函数<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220358799-222018244.png"></p>
<p>②、第2次进入read()函数(<em><strong>重点是当前正在使用的被装饰的输入Stream中的字节数据已经读取完了时,再次读取,会返回-1,不会返回0</strong></em>)<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220444027-114156103.png"></p>
<p>③、第3次进入read()函数<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220454388-832370963.png"></p>
<p>④、第4次进入read()函数(<em><strong>重点是当前正在使用的被装饰的输入Stream中的字节数据已经读取完了时,再次读取,会返回-1,不会返回0</strong></em>)<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220519251-804438398.png"></p>
<p>最终使用者创建的byte[]数组中的字节(byte)数据,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220532858-840425074.png"></p>
<h6 id="121使用举例">1.2.1、使用举例</h6>
<p> 下面这个例子就恰当的使用SequenceInputStream的read()函数;</p>
<ul>
<li>
<p>我的windows操作系统的D盘根目录下有2个txt文件,一个是data1.txt,另一个是data2.txt文件,这2个文件中总共有30个字节,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220203616-2107974847.png"><br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220213513-1764667319.png"></p>
</li>
<li>
<p>使用者可以用一个SequenceInputStream对象装饰2个被装饰的输入Stream(此处为FileInputStream),如下代码所示:</p>
</li>
</ul>
<pre><code>package com.chelong.StreamAndReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.util.Vector;
public class SequenceInputStreamTest {
public static void main(String[] args) {
InputStream is1 = null;
InputStream is2 = null;
SequenceInputStream sequenceInputStream = null;
try {
is1 = new FileInputStream("D:\\data1.txt");
is2 = new FileInputStream("D:\\data2.txt");
Vector<InputStream> vector = new Vector<InputStream>();
vector.addElement(is1);
vector.addElement(is2);
sequenceInputStream = new SequenceInputStream(vector.elements());
int readByte = -1;
byte[] buff = new byte;
while ((readByte = sequenceInputStream.read(buff, 0, buff.length)) != -1) {
for (int i = 0; i < readByte; i++) {
System.out.print((char) buff);
}
}
System.out.println();
System.out.println("最终留在byte[]数组buff中的字节:");
for (byte b : buff) {
System.out.print((char) b);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is1 != null) is1.close();
if (is2 != null) is1.close();
if (sequenceInputStream != null) sequenceInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
</code></pre>
<p>程序运行结果,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220724112-1904589148.png"></p>
<h4 id="二vectorclass的一些函数说明">二、Vector.class的一些函数说明</h4>
<p> Vector 与 ArrayList 一样,也是通过数组实现的,不同的是它支持线程的同步,即某一时刻只有一个线程能够写 Vector,避免多线程同时写而引起的不一致性,但实现同步需要很高的花费,因此,访问它比访问 ArrayList慢。Vector的UML图,如下所示:<br>
<img src="https://img2024.cnblogs.com/blog/2485827/202602/2485827-20260215220751217-1800828263.png"></p>
<h5 id="21构造函数">2.1、构造函数</h5>
<table>
<thead>
<tr>
<th style="text-align: left">函数名</th>
<th style="text-align: left">函数说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">public Vector()</td>
<td style="text-align: left">此构造函数创建的Vector中,Object[]数组的初始长度为10,capacityIncrement=0(capacityIncrement表示扩容时Object[]数组增加的长度,如果等于0的话,当Object[]数组需要扩容时,新的数组长度=2*旧数组的长度,但是新的数组长度最大为2^31-8)</td>
</tr>
<tr>
<td style="text-align: left">public Vector(int initialCapacity)</td>
<td style="text-align: left">此构造函数创建的Vector中,Object[]数组的初始长度为initialCapacity,capacityIncrement=0(capacityIncrement表示扩容时Object[]数组增加的长度,如果等于0的话,当Object[]数组需要扩容时,新的数组长度=2*旧数组的长度,但是新的数组长度最大为2^31-8)</td>
</tr>
<tr>
<td style="text-align: left">public Vector(int initialCapacity, int capacityIncrement)</td>
<td style="text-align: left">此构造函数创建的Vector中,Object[]数组的初始长度为initialCapacity,capacityIncrement=capacityIncrement(capacityIncrement表示扩容时Object[]数组增加的长度,如果等于0的话,当Object[]数组需要扩容时,新的数组长度=2*旧数组的长度,但是新的数组长度最大为2^31-8)</td>
</tr>
<tr>
<td style="text-align: left">public Vector(Collection<? extends E> c)</td>
<td style="text-align: left">此构造函数创建的Vector中,Object[]数组的初始长度为传入集合Collection<? extends E> c的长度,capacityIncrement=0(capacityIncrement表示扩容时Object[]数组增加的长度,如果等于0的话,当Object[]数组需要扩容时,新的数组长度=2*旧数组的长度,但是新的数组长度最大为2^31-8)</td>
</tr>
</tbody>
</table>
<p>2.2、常用函数</p>
<table>
<thead>
<tr>
<th style="text-align: left">函数名</th>
<th style="text-align: left">函数说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">boolean add(E o)</td>
<td style="text-align: left">此函数将指定的元素追加到此Vector的末尾,该函数与addElement()函数的区别是,该()函数是List.interface接口规定的函数,addElement()函数是Vector自己实现的(接口中没有规定addElement()函数)</td>
</tr>
<tr>
<td style="text-align: left">void add(int index, E element)</td>
<td style="text-align: left">此函数将指定的元素插入此Vector中的指定索引位置</td>
</tr>
<tr>
<td style="text-align: left">boolean addAll(Collection<? extends E> c)</td>
<td style="text-align: left">此函数将指定Collection中的所有元素追加到此Vector的末尾</td>
</tr>
<tr>
<td style="text-align: left">boolean addAll(int index, Collection<? extends E> c)</td>
<td style="text-align: left">此函数将指定Collection中的所有元素插入到此Vector中的指定索引位置</td>
</tr>
<tr>
<td style="text-align: left">void addElement(E obj)</td>
<td style="text-align: left">此函数将指定的元素追加到此Vector的末尾,这个函数与add()函数的区别是,add()函数是List.interface接口规定的函数,这个函数是Vector自己实现的(接口中没有规定该函数)</td>
</tr>
<tr>
<td style="text-align: left">int capacity()</td>
<td style="text-align: left">此函数返回此Vector的当前容量</td>
</tr>
<tr>
<td style="text-align: left">void clear()</td>
<td style="text-align: left">此函数从此Vector中删除所有元素</td>
</tr>
<tr>
<td style="text-align: left">Object clone()</td>
<td style="text-align: left">此函数返回此Vector的克隆对象</td>
</tr>
<tr>
<td style="text-align: left">boolean contains(Object elem)</td>
<td style="text-align: left">如果此Vector包含指定的元素,则此函数返回true</td>
</tr>
<tr>
<td style="text-align: left">boolean containsAll(Collection<?> c)</td>
<td style="text-align: left">如果此Vector包含指定Collection中的所有元素,则此函数返回true</td>
</tr>
<tr>
<td style="text-align: left">void copyInto(Object[] anArray)</td>
<td style="text-align: left">此方法将此向量的组件复制到指定的数组中</td>
</tr>
<tr>
<td style="text-align: left">E elementAt(int index)</td>
<td style="text-align: left">此函数返回Vector指定索引处的元素</td>
</tr>
<tr>
<td style="text-align: left">Enumeration<e> elements()</e></td>
<td style="text-align: left">此函数返回此Vector中所包含的所有元素的枚举。</td>
</tr>
<tr>
<td style="text-align: left">void ensureCapacity(int minCapacity)</td>
<td style="text-align: left">此函数可增加此Vector的容量,以确保它至少可以保存最小容量元素个数</td>
</tr>
<tr>
<td style="text-align: left">boolean equals(Object o)</td>
<td style="text-align: left">此函数将指定的Object与此Vector进行比较以获得相等性</td>
</tr>
<tr>
<td style="text-align: left">E firstElement()</td>
<td style="text-align: left">返回此Vector的第一个元素(位于Object[]数组索引 0 处的元素)</td>
</tr>
<tr>
<td style="text-align: left">E get(int index)</td>
<td style="text-align: left">返回Vector中指定索引位置的元素</td>
</tr>
<tr>
<td style="text-align: left">int indexOf(Object elem)</td>
<td style="text-align: left">搜索给定参数的第一个匹配项,使用 equals ()函数测试相等性</td>
</tr>
<tr>
<td style="text-align: left">int indexOf(Object elem, int index)</td>
<td style="text-align: left">搜索给定参数的第一个匹配项,从 index 处开始搜索,并使用 equals()函数测试其相等性</td>
</tr>
<tr>
<td style="text-align: left">void insertElementAt(E obj, int index)</td>
<td style="text-align: left">将指定对象作为此Vector中的元素插入到指定的 索引位置</td>
</tr>
<tr>
<td style="text-align: left">boolean isEmpty()</td>
<td style="text-align: left">测试此Vector中的是否不包含任何元素</td>
</tr>
<tr>
<td style="text-align: left">E lastElement()</td>
<td style="text-align: left">返回此Vector的最后一个元素(位于Object[]数组索引 Object[].length-1 处的元素)</td>
</tr>
<tr>
<td style="text-align: left">int lastIndexOf(Object elem)</td>
<td style="text-align: left">返回指定的对象在此Vector中最后一个匹配项的索引</td>
</tr>
<tr>
<td style="text-align: left">int lastIndexOf(Object elem, int index)</td>
<td style="text-align: left">从指定的索引处开始向后搜索指定的对象,并返回搜索到的最后一个索引</td>
</tr>
<tr>
<td style="text-align: left">E remove(int index)</td>
<td style="text-align: left">移除此Vector中指定索引位置的元素</td>
</tr>
<tr>
<td style="text-align: left">boolean remove(Object o)</td>
<td style="text-align: left">移除此Vector中指定元素的第一个匹配项,如果此Vector不包含该元素,则所有元素保持不变,并返回false</td>
</tr>
<tr>
<td style="text-align: left">boolean removeAll(Collection<?> c)</td>
<td style="text-align: left">从此Vector中移除包含在指定 Collection 中的所有元素</td>
</tr>
<tr>
<td style="text-align: left">void removeAllElements()</td>
<td style="text-align: left">从此Vector中移除全部元素,并设置elementCount=0(该变量表示此Vector对象中有效元素的数量),Object[]数组的长度不变。</td>
</tr>
<tr>
<td style="text-align: left">void removeElementAt(int index)</td>
<td style="text-align: left">删除指定索引处的元素</td>
</tr>
<tr>
<td style="text-align: left">protected void removeRange(int fromIndex, int toIndex)</td>
<td style="text-align: left">从此 Vector 中移除索引位于 [fromIndex, toIndex)(左闭右开)之间的所有元素</td>
</tr>
<tr>
<td style="text-align: left">boolean retainAll(Collection<?> c)</td>
<td style="text-align: left">如果此Vector中包含指定 Collection 中的所有元素,此函数返回true</td>
</tr>
<tr>
<td style="text-align: left">E set(int index, E element)</td>
<td style="text-align: left">用指定的元素替换此Vector中指定索引处的元素</td>
</tr>
<tr>
<td style="text-align: left">void setElementAt(E obj, int index)</td>
<td style="text-align: left">将此Vector指定 索引处的元素设置为指定的另一个元素</td>
</tr>
<tr>
<td style="text-align: left">void setSize(int newSize)</td>
<td style="text-align: left">设置此Vector的大小</td>
</tr>
<tr>
<td style="text-align: left">int size()</td>
<td style="text-align: left">返回此Vector中的元素数</td>
</tr>
<tr>
<td style="text-align: left">List<e> subList(int fromIndex, int toIndex)</e></td>
<td style="text-align: left">返回此 Vector的子集,该子集的元素范围为 [fromIndex, toIndex)(左闭右开)索引位置的所有元素</td>
</tr>
<tr>
<td style="text-align: left">Object[] toArray()</td>
<td style="text-align: left">返回一个Object[]数组,包含此Vector中以正确顺序存放的所有元素</td>
</tr>
<tr>
<td style="text-align: left">String toString()</td>
<td style="text-align: left">返回此Vector的字符串表示形式,其中包含每个元素的 String 表示形式</td>
</tr>
</tbody>
</table><br><br>
来源:https://www.cnblogs.com/Carey-ccl/p/19618752
頁:
[1]