I am using the following code:
final UnassignedSubjectData selsub = (UnassignedSubjectData) spinSelectSubject
.getSelectedItem();
ArrayList<UnassignedSubjectData> selectedSubjectList = null;
if (selsubdata != null) {
selectedSubjectList = new ArrayList<UnassignedSubjectData>(
Arrays.asList(selsubdata));
Log.d(LOGTAG, "Check " + selsub.toString());
Log.d(LOGTAG, "Check " + selectedSubjectList.toString());
Log.d(LOGTAG, "Result for if "
+ Arrays.asList(selsubdata).contains(Arrays.asList(selsub)));
if (selectedSubjectList.contains(Arrays.asList(selsub))) {
CustomToast.showCustomToast(this,
"Subject already present in list");
Log.d(LOGTAG,
"IN IF after TOAST " + selectedSubjectList.toString());
return;
}
else
Log.d(LOGTAG, "Showing subject not in list");
}
The selsub
is an object of UnassignedSubjectData
.
I get the following in the for one of the conditions in LogCat:
Check History
Check [History, Science, Science, History]
Result for if false
Showing subject not in list
That means even when the object is present in the ArrayList
the .contains()
operator is not working properly.
Please help me find a solution for this.