【发布时间】:2014-08-23 11:49:15
【问题描述】:
我有一个下面提到的数组列表结构。
ArrayList<Arraylisttableitem> tablestatuslist = new ArrayList<Arraylisttableitem>();
下面提到了这个数组列表的模型类。
public class Arraylisttableitem {
String total, noofcustomer, firstname, tab_name, balance, time;
public Arraylisttableitem(String total, String noofcustomer,
String firstname, String tab_name, String balance, String time) {
// TODO Auto-generated constructor stub
this.total = total;
this.noofcustomer = noofcustomer;
this.firstname = firstname;
this.tab_name = tab_name;
this.balance = balance;
this.time = time;
}
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public String getNoofcustomer() {
return noofcustomer;
}
public void setNoofcustomer(String noofcustomer) {
this.noofcustomer = noofcustomer;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getTab_name() {
return tab_name;
}
public void setTab_name(String tab_name) {
this.tab_name = tab_name;
}
public String getBalance() {
return balance;
}
public void setBalance(String balance) {
this.balance = balance;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
}
在名为 tab_name 的元素中,我可能有重复的元素。我想识别重复的元素并添加所有重复的值。示例 tab_num 10 的余额为 5,而 tab_num 10 的余额为 10。我想要的是 tab_nam 10 应该出现一次,并且余额应该是 15,并且列表中没有任何重复值。
请解决我的问题...
我不知道在里面写什么..
for(Arraylisttableitem itemlist : tablestatuslist)
{
}
我的 JSON 有重复值。所以,我的数组列表支持重复值。
【问题讨论】:
-
当您将对象添加到数组列表时,为什么不处理这种情况,而不是稍后删除重复项?
-
@ShivamVerma 这会在每次添加数据时减慢整个操作。
标签: java android collections arraylist core