我有一个 Java 程序,它通过将数据从数据库获取到 List
来运行。的Entity
s。我们使用实体类Customer
,以及 List<Customer>
.
我现在有来自日志文件的数据。我需要构建一个 List<Customer>
使用此数据。
我该怎么做?
目前,我已经
List<Customer> c1= cDao.getAllElements(SQL);
// process c1
我正在使用开源文件解析器 OpenCSV 读取具有非常相似数据元素的日志文件。
我想创建一个类似的List
,说:
List<Customer> c2 = getElementsFromLog();
有没有办法可以构建这样一个List<Customer>
?我怎样才能做到这一点?
最佳答案
List<Customer> c2 = new ArrayList<Customer>(); //Or any other class implementing List
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
String [] nextLine;
while ((nextLine = reader.readNext()) != null) {
Customer c = new Customer(nextLine); //Or create a new Customer in some way
c2.add(c);
}
关于java - 将元素添加到实体对象java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25575380/