Most efficient way of converting String to Integer in java

后端 未结 11 2056
面向向阳花
面向向阳花 2020-11-29 08:00

There are many ways of converting a String to an Integer object. Which is the most efficient among the below:

Integer.valueOf()
Integer.parseInt()
org.apache         


        
11条回答
  •  情书的邮戳
    2020-11-29 08:41

    Don't even waste time thinking about it. Just pick one that seems to fit with the rest of the code (do other conversions use the .parse__() or .valueOf() method? use that to be consistent).

    Trying to decide which is "best" detracts your focus from solving the business problem or implementing the feature.

    Don't bog yourself down with trivial details. :-)

    On a side note, if your "use case" is specifying java object data types for your code - your BA needs to step back out of your domain. BA's need to define "the business problem", and how the user would like to interact with the application when addressing the problem. Developers determine how best to build that feature into the application with code - including the proper data types / objects to handle the data.

提交回复
热议问题