I just want to check if the data already exists or not in the ArrayList, but each time it turns out: Not Exist (s), while the data exists in the ArrayList, and as a result I get duplicate entries in the list.
DataArrayList.secondArraylist.add(new Second(actorList.get(position).getName(), actorList.get(position).getImage()));
System.out.println(DataArrayList.secondArraylist.size());
String strName = actorList.get(position).getName().toString();
Log.d("name:", strName);
for(int i=0; i<DataArrayList.secondArraylist.size(); i++)
{
if(DataArrayList.secondArraylist.get(i).getName().equals(strName)) {
System.out.println(DataArrayList.secondArraylist.get(i).getName());
Toast.makeText(context, "Exist(s)", Toast.LENGTH_SHORT);
}
else {
Toast.makeText(context, "Not Exist(s)", Toast.LENGTH_SHORT);
}
}
Problem:
Do not receive Toast, which I use to indicate that "Data Exists" or "Not"
Finally:
I would like to add an element to arraylist if it already does not exist, otherwise you want to show Toast that the element already exists
Oreo source
share