I’m fetching the location names from the database in the form of comma separated string. I’m comparing this string with an ArrayList of string that contains the location names that I’ve entered to check if the entered location names are same as that of the ones in database. To do this I’m using the below code. But it doesn’t seem to work. Kindly let me how could i go about it. I used equals() as well, but it ain’t working fine.
String loc =DataHelperdh.getLocationList(id); // loc holds the comma separated locations
for (int i2 = 0; i2 < locationList.size(); i2++)
{
if(locationList.get(i2)==null || locationList.get(i2).equals(""))continue;
String str1 =loc.toString();
int result = str1.indexOf(locationList.get(i2));
if(result > -1){
Toast.makeText(getApplicationContext(), "Locations with same name cannot exist same", Toast.LENGTH_LONG).show();
break;
}
}
you check if
str1contains the whole list which is very unlikely. It should work if you turn it around.