如何解决从列表Android比较用户ID和日期后,删除旧对象?
我的数组列表中有类似这样的数据。
我已经尝试过此代码。
Collections.sort(streamList,new Comparator() {
@Override
public int compare(Object o1,Object o2) {
Stream p1 = (Stream) o1;
Stream p2 = (Stream) o2;
return p1.getName().compareToIgnoreCase(p2.getName());
}
});
List<Stream> streamList = new ArrayList<>();
在删除具有相同userId的旧日期重复值之前:
[
{
"userName": "25","Date": "Thu Aug 20 18:38:54 GMT+05:30 2020"
},{
"userName": "26","Date": "Thu Aug 20 18:38:55 GMT+05:30 2020"
},{
"userName": "27","Date": "Thu Aug 20 18:38:56 GMT+05:30 2020"
},{
"userName": "28",{
"userName": "29","Date": "Thu Aug 20 18:38:57 GMT+05:30 2020"
},{
"userName": "30","Date": "Thu Aug 20 18:38:58 GMT+05:30 2020"
},"Date": "Thu Aug 20 18:39:50 GMT+05:30 2020"
},"Date": "Thu Aug 20 18:39:56 GMT+05:30 2020"
}
]
在删除具有相同userId的旧日期重复值之后的预期输出:
[
{
"userName": "25","Date": "Thu Aug 20 18:39:56 GMT+05:30 2020"
}
]
Stream.java
public class Stream {
/** Property userName */
String userName;
/** Property date */
Date date;
/**
* Constructor
*/
public Stream() {
}
/**
* Gets the userName
*/
public String getUserName() {
return this.userName;
}
/**
* Sets the userName
*/
public void setUserName(String value) {
this.userName = value;
}
/**
* Gets the Date
*/
public Date getDate() {
return this.date;
}
/**
* Sets the Date
*/
public void setDate(Date value) {
this.date = value;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。