gpt4 book ai didi

java : mapping the Values from Enumeration to Object

转载 作者:行者123 更新时间:2023-12-02 07:54:33 34 4
gpt4 key购买 nike

我有一个枚举,如下面的程序所示

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 实现可能会更好。

关于java : mapping the Values from Enumeration to Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9806887/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com