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分的结果:如何与列表<string[]> java的比较数组列表
阵列数据 - >[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
中的每个元素进行比较。
您必须比较每个元素。干净的方法是创建比较函数来识别更新和添加的数据 – Tala