Comparing String and Integer with equals

后端 未结 4 1670
一个人的身影
一个人的身影 2021-01-13 23:02

The output of the below code is false

String str = \"3456\";
String str1 = \"3456\";
System.out.println(Integer.valueOf(str).equals(str1));
         


        
4条回答
  •  温柔的废话
    2021-01-13 23:46

    a Integer Object can't equals with String Object

    use :

    boolean a = str.equals(str1);
    

    OR

    boolean a = (Integer.parseInt(str) == Integer.parseInt(str1));
    

提交回复
热议问题