我有一个枚举,如下面的程序所示
public class Test {
public static void main(String args[]) {
Vector v = new Vector();
v.add("Three");
v.add("Four");
v.add("One");
v.add("Two");
Enumeration e = v.elements();
load(e) ; // **Passing the Enumeration .**
}
}
还有一个学生对象
public Student
{
String one ;
String two ;
String three ;
String four ;
}
我需要将此枚举传递给另一种方法,如下所示
private Data load(Enumeration rs)
{
Student stud = new Student();
while(rs.hasMoreElements())
{
// Is it possible to set the Values for the Student Object with appropiate values I mean as shown below
stud.one = One Value of Vector here
stud.two = Two Value of Vector here
stud.three = Three Value of Vector here
stud.four = Four Value of Vector here
}
}
请就此分享您的想法。
谢谢
最佳答案
当然。您可以使用elementAt
方法documented here来获取所需的值。您有使用Vector的特定原因吗?一些List
实现可能更好。