Strings don't seem to be equal in Java on Android, even though they print the same

孤街浪徒 提交于 2019-11-30 11:34:19

Use String's equals method to compare Strings. The == operator will just compare object references.

if ( CurrentNode.getNodeName().toString().equals("start") ) {
   ...

Use CurrentNode.getNodeName().toString().equals("start").

In Java, one of the most common mistakes newcomers meet is using == to compare Strings. You have to remember, == compares the object identity (Think memory addresses), not the content.

You need to use .equals

if ("start".equals(CurrentNode.getNodeName().toString()) { ... }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!