Best performance for string to boolean conversion

后端 未结 3 1921
青春惊慌失措
青春惊慌失措 2021-01-19 13:23

Which has best performance while converting String to boolean from the below options.

  1. boolean value = new Boolean(\"true\").booleanValue();
  2. <
3条回答
  •  青春惊慌失措
    2021-01-19 14:02

    The second and third one are the best options since they are static factory methods and internally the can reuse references.

    Looking at Boolean.valueOf("true") and Boolean.parseBoolean("true") implementations they both do the same (they both call toBoolean(s);) with the difference that valueOf returns the Boxed type.

提交回复
热议问题