I'm trying to hold a set of ID's in an ArrayList I then want to compare the current value with the contents of said Arraylist, but it doesn't seem to work for me.
Both my methods are not working, in the code snippets c.getString(0) is pulling the Numeric ID column from a SQLite Database, and allProgramIds contains the same ID.
method 1. straight Comparison (this doesn't match, just ignores)
for(int i=0;i<allProgramIds.size();i++) {
Log.w(TAG, "Looping - looking for:" + c.getString(0) + ", Holding:"+allProgramIds);
if( allProgramIds.get(i) == c.getString(0)) {
exist=true;
Log.w(TAG, "Found one:" + c.getString(0));
break;
}
}
method 2. Casting to Int before Comparison (this causes crash)
for(int i=0;i<allProgramIds.size();i++) {
Log.w(TAG, "Looping - looking for:" + c.getString(0) + ", Holding:"+allProgramIds);
if( Integer.toString((Integer) allProgramIds.get(i)) == c.getString(0)) {
exist=true;
Log.w(TAG, "Found one:" + c.getString(0));
break;
}
}
here is a log output
Log.w(TAG, "Looping - looking for:" + c.getString(0) + ", Holding:"+allProgramIds);
04-04 10:43:42.805: W/MainProgram(2045): Looping - looking for:73, Holding:[68, 69, 70, 71, 72, 73, 74, 75, 76, 68, 69, 70, 71, 72]
thanks