还有,字符串对象元素却在本例中能够搜索得到,
Vector vt=new Vector();
vt.add(new String("dog"));
vt.add(new String("pig"));
print(vt.indexOf(new String("dog")));//搜索到,返回0
print(vt.indexOf("pig"));//搜索到,返回1
不知道为什么??
Vector vt=new Vector();
vt.add(new String("dog"));
vt.add(new String("pig"));
print(vt.indexOf(new String("dog")));//搜索到,返回0
print(vt.indexOf("pig"));//搜索到,返回1
不知道为什么??
public static void main(String[] args){
Vector v=new Vector(); for(int i=0;i<3;i++)
{
VectorTest a=new VectorTest(i);
//int[] arr={0,i};
//v.add(new VectorTest(i));
v.add(a);
//print(v.contains(new VectorTest(i) ));
print(v.contains(a));
}
v.add(1,new VectorTest(123)); Enumeration e=v.elements(); //将生成的vector元素列表赋给e
while(e.hasMoreElements())
((VectorTest)e.nextElement()).print();//必须类型造型,否则出错:
//究其原因:类型信息丢失在对象vector后
print(v.size());
public static void main(String[] args){
Vector v=new Vector();
for(int i=0;i<3;i++)
{
VectorTest a=new VectorTest(i);
v.add(a);
print(v.contains(a)); //true,successful!
}
print(v.indexOf(new VectorTest(1)));//-1,failure!
print(v.indexOf(new VectorTest(2)));//-1,failure!
print(v.contains(new VectorTest(2)));//false,failure!
VectorTest flag=new VectorTest(123);
v.add(flag);
print(v.contains(flag));//true,successful!
print(v.indexOf(flag)); //3,successful!
Enumeration e=v.elements(); //将生成的vector元素列表赋给e
while(e.hasMoreElements())
((VectorTest)e.nextElement()).print();//必须类型造型,否则出错:
//究其原因:类型信息丢失在对象vector后
print(v.size());
}
真搞不懂了,JAVA就这么弱智吗??
print(v.contains(new VectorTest(2)));//false,failure!
没有给变量名就查找失败???up!!
给出变量名就查找成功》》look down!! VectorTest flag=new VectorTest(123);
v.add(flag);
print(v.contains(flag));//true,successful!
Vector v=new Vector(); VectorTest[] a=new VectorTest[3];
for(int i=0;i<3;i++)
{
a[i]=new VectorTest(i);
v.add(a[i]);
print(v.contains(a[i]));
}
v.add(1,new VectorTest(123));//下标为1的数组前插入元素
Enumeration e=v.elements(); //将生成的vector元素列表赋给e
while(e.hasMoreElements())
((VectorTest)e.nextElement()).print();//必须类型造型,否则出错:
//究其原因:类型信息丢失在对象vector后
print(v.size()); //vector中元素个数 //v.clear(); //清空vector列表中所有元素
print(v.isEmpty()); //判断vector列表是否为空
print(v.contains(a[2]));//判断是否含有特定的对象元素;搜索不到((VectorTest)v.get(3)).print(); //取得vector列表中下标为3的数组的元素
VectorTest vs=new VectorTest(123);
//print(v.contains(vs));
print(v.indexOf(a[1]));//判断是否含有特定的对象元素;搜索不到