I have a problem with Integer.toString conversion. This code outputs "ololo". Why? And how can I convert integer to string right?
String str1= "1";
String str2=Integer.toString(1);
if (str1!=str2)Log.d("myLogs","ololo");
You must compare Strings using equals method, not == nor != operators since they will compare the String object references.
if (!str1.equals(str2)) {
Log.d("myLogs","ololo");
}
Note that when you use Integer#toString you're creating a new String that is not in the String JVM pool, thus getting the error described.
字符串比较必须用equals来完成。
if (!str1.equals(str2))...
当你使用!=你得到引用相等(不等式)
尝试String.valueOf(1);将整数更改为字符串。
改为使用!str1.equals(str2)。
你不应该使用==or!=字符串