Java: Comparing ints and Strings - Performance

后端 未结 3 881
孤街浪徒
孤街浪徒 2020-12-18 19:33

I have a String and an int, lets say: String str = \"12345\"; and int num = 12345;. What is the fastest way of seeing if they are the same, s

3条回答
  •  感情败类
    2020-12-18 19:35

    I think num == Integer.parseInt(str) is a better way of doing comparison. Because str.equals("" + num) this is not the ideal way how you should compare integer values and also it will create unnecessary String constant objects in the String pool (which hampers performance).

提交回复
热议问题