Why is the IF statement inside my For Loop never meeting its condition?

java

Solution

Remove the semicolon at the end of your if statement:

 if (goingToId.equals(objarray.get(i).getid()))

Problem

I have tried everything and I just cannot see why I am getting this issue. Here is the code I am using: ``` for( int i=0; i< objarray.size();i++) { //Toast shows values Toast.makeText(getApplicationContext(), goingToId+""+objarray.get(i).getid(),Toast.LENGTH_SHORT).show(); if (goingToId == objarray.get(i).getid()) { //This Toast NEVER shows Toast.makeText(getApplicationContext(), "Inside the if statement",Toast.LENGTH_SHORT).show(); glat = objarray.get(i).getlat(); glon = objarray.get(i).getlon(); loc = new Location("dummyprovider"); loc.setLatitude(glat); loc.setLongitude(glon); } } ``` Both of the values being compared are strings. In the for loop, the two values are output in toasts and i can clearly see when the two are the same value, but the for loop always finishes without ever entering the IF statement, or the IF statement never meets its condition, but I don't know why. I do this kind of thing all the time in C# and it always works, can anyone see why this would not be working in Android? I understand there is not much information to go on in my post, but you can trust me when I say that they values do eventually match while iterating through the for loop. Any advice would be appreciated as I am clueless.

Original source