嗨,我是 java 新手,我现在正在向量中添加对象,我正在添加两个对象,但是如果我想通过文件或数据库输入千人的数据,我现在该怎么做,我有三个类. 和代码如下: -
public class Customer {
private int custid;
private String custname;
private float custsalary;
public String toString() {
StringBuffer buffer = new StringBuffer();
buffer.append("Customer Id :=" + custid+"\n");
buffer.append("Customer Name :=" + custname+"\n");
buffer.append("Customer Salary :=" + custsalary+"\n");
return buffer.toString();
}
public int getCustid() {
return custid;
}
public void setCustid(int custid) {
this.custid = custid;
}
public String getCustname() {
return custname;
}
public void setCustname(String custname) {
this.custname = custname;
}
public float getCustsalary() {
return custsalary;
}
public void setCustsalary(float custsalary) {
this.custsalary = custsalary;
}
}
第二类是
package com.test.collection.list.vector.custom;
import java.util.Enumeration;
import java.util.Vector;
public class CustomerVector {
public void custDetails(){
Customer c1Obj = new Customer();
c1Obj.setCustid(123);
c1Obj.setCustname("Kb");
c1Obj.setCustsalary(1000.34f);
Customer c2Obj = new Customer();
c2Obj.setCustid(456);
c2Obj.setCustname("nv");
c2Obj.setCustsalary(2000.34f);
Vector<Customer> v = new Vector<Customer>();
v.addElement(c1Obj);
v.addElement(c2Obj);
Enumeration<Customer> custEnum = v.elements();
while (custEnum.hasMoreElements()) {
Customer customer = custEnum.nextElement();
System.out.println(customer);
}
}
}
这是我的客户代码
package com.test.collection.list.vector.custom;
public class ClientCode {
public static void main(String[] args) {
CustomerVector custVectObj = new CustomerVector();
custVectObj.custDetails();
}
}
我的问题是,如果我想添加千人的数据,最简单有效的方法是什么