在我的Android应用程序中,我想检查,如果一个值已经在我的数组列表中。
我试过这样的事情:private List<Values> retrieve() {
List<Values> list = new ArrayList<>();
int x = 0;
while (x < Values.length) {
if (list.contains(new Values(Values[x]))) {
Log.e("-->", "DUPLICATE: "+Values[x]);
} else {
Log.e("-->", "NEW: "+Values[x]);
list.add(new Values(Values[x]));
}
x++;
}
return list;
}
我的ArrayList&#34;值&#34;的内容:
最大,萨宾,克里斯,最大值,最大值
但我总是得到Log&#34; NEW&#34;。 但这不对。价值&#34; Max&#34;是重复的。
我的错误是什么?
答案 0 :(得分:0)
不要创建新对象。
curl -XGET 'http://localhost:9200/employee/_search?search_type=count&pretty&source={"aggregations":{"profile":{"terms":{"field":"_type"},"aggs":{"hits":{"top_hits":{"size":1}}}}}}'
^
|
use the source parameter
但最好是不允许存储重复项。您可以使用source
query string parameter(如果您需要订购)。否则只需int x = 0;
while (x < Values.length) {
if (list.contains(Values[x])) {
Log.e("-->", "DUPLICATE: "+Values[x]);
} else {
Log.e("-->", "NEW: "+Values[x]);
list.add(Values[x]);
}
x++;
}
return list;
即可。