List<String[]> sarray;
ArrayList<ContentTable> currentData=new ArrayList<ContentTable>();
//here sarray is initialized with data
sarray = reader.readAll();
for(String[] arr : sarray)
{
System.out.println("array data "+ Arrays.toString(arr));
}
for(ContentTable ct : currentData)
{
System.out.println("list data "+ct.getId() +" "+ ct.getSubid() +" "+ct.getChpid()+" "+ct.getSec_name()+" "+ct.getContent());
}
输出数组和列表的 1 个结果:
数组数据-> [9, 10, 83, Concepts: 1-10, <p>We’ll discuss many of the concepts in this chapter in depth later. But for now, we need a brief review of these concepts to equip you for solving exercises in the chapters that follow.</p>]
列出数据-> 9 10 83 Concepts: 1-10 <p>We’ll discuss many of the concepts in this chapter in depth later. But for now, we need a brief review of these concepts to equip you for solving exercises in the chapters that follow.</p>
//fields with getters and setters in ContentTable Class
public class ContentTable {
int id;
int subid;
int chpid;
String sec_name;
String content;
}
现在我想要实现的是创建两个列表,
ArrayList<ContentTable> updatedData=new ArrayList<ContentTable>();
ArrayList<ContentTable> addedData=new ArrayList<ContentTable>();
这些将在比较之后填充数据,sarray
并且currentdata
以这样的方式,
如果ct.getSec_name()
或ct.getContent()
在特定索引currentdata
处不等于存在的数据,sarray
则将其添加到updatedData
和,
如果ct.getId()
, ct.getSubid()
,ct.getChpid()
在特定索引处不等于任何sarray
数据,那么它将被添加到 addedData
以较低的复杂性来做这件事的优雅方法是什么,我想以最快的速度做到这一点,因为可能需要时间来比较每个元素Arraylist currentData
以与ArrayList sarray
.