当前位置: 技术问答>java相关
一个Vector应用的问题
来源: 互联网 发布时间:2015-11-10
本文导语: 下面是两个类,一个vector,一个基类!我依次取出其中的值,却得到的是最后一次加进去的值; //vector package com.data; import java.util.*; public class ViewGroup { private Vector view; public ViewGroup() { v...
下面是两个类,一个vector,一个基类!我依次取出其中的值,却得到的是最后一次加进去的值;
//vector
package com.data;
import java.util.*;
public class ViewGroup
{
private Vector view;
public ViewGroup()
{
view=new Vector();
}
public boolean add(ViewModel viewm)
{
return view.add(viewm);
}
public int size()
{
return view.size();
}
public ViewModel get(int index)
{
return (ViewModel)view.get(index);
}
}
//基类
package com.data;
public class ViewModel
{
private int order;
public ViewModel() {
}
public void setOrder(int order)
{
this.order = order;
}
public int getOrder()
{
return (this.order);
}
}
我在应用时如下:
ViewGroup viewg=new ViewGroup();
ViewModel viewm=new ViewModel();
while(rs.next()){
viewm.setOrder(rs.getString("id"));
viewg.add(viewm);
}
for(int i=0;i
//vector
package com.data;
import java.util.*;
public class ViewGroup
{
private Vector view;
public ViewGroup()
{
view=new Vector();
}
public boolean add(ViewModel viewm)
{
return view.add(viewm);
}
public int size()
{
return view.size();
}
public ViewModel get(int index)
{
return (ViewModel)view.get(index);
}
}
//基类
package com.data;
public class ViewModel
{
private int order;
public ViewModel() {
}
public void setOrder(int order)
{
this.order = order;
}
public int getOrder()
{
return (this.order);
}
}
我在应用时如下:
ViewGroup viewg=new ViewGroup();
ViewModel viewm=new ViewModel();
while(rs.next()){
viewm.setOrder(rs.getString("id"));
viewg.add(viewm);
}
for(int i=0;i