Universal Robots Forum

Comparison of Strings

I am trying to compare two strings, in the terminal they seems to be the same, but the comparison returns false. Is there some encoding or something I need to be aware of, to be able to do this?

Udklip

private void setSelectedFeature(String F)
	{
		String oldFeature = getSelectedFeature();
		String newFeature = F;
		
		System.out.println("Old feature: " + oldFeature);
		System.out.println("New feature: " + newFeature);
		
		if (oldFeature.trim() != newFeature.trim())
		{
			model.set(SELECTED_VAR, F);
			System.out.println("Saved feature in model: " + F);
		}
		else
		{
			System.out.println("No need to save feature in model: " + F);
		}
	}

Update:
It works with this

private void setSelectedFeature(String F)
	{
		String oldFeature = getSelectedFeature();
		String newFeature = F;
		
		System.out.println("Old feature: " + oldFeature);
		System.out.println("New feature: " + newFeature);
		
		if (!oldFeature.equals(newFeature))
		{
			model.set(SELECTED_VAR, F);
			System.out.println("Saved feature in model: " + F);
		}
		else
		{
			System.out.println("No need to save feature in model: " + F);
		}
	}

But can someone explain why it works with .equals() but not == ?