在java中将String转换为Integer的最有效方法 [英] Most efficient way of converting String to Integer in java

查看:220
本文介绍了在java中将String转换为Integer的最有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将String转换为Integer对象的方法有很多种。以下哪个是效率最高的:

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.commons.beanutils.converters.IntegerConverter

我的用例需要创建包装器Integer对象。 ..没有原始的int ...并且转换的数据用于只读。

My usecase needs to create wrapper Integer objects...meaning no primitive int...and the converted data is used for read-only.

推荐答案

甚至不要浪费时间思考它。只需选择一个似乎与其余代码相符的内容(其他转换使用.parse __()或.valueOf()方法吗?使用它来保持一致)。

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. :-)

在旁注中,如果您的用例为您的代码指定了java对象数据类型 - 您的BA需要退出您的域。 BA需要定义业务问题,以及用户在解决问题时如何与应用程序进行交互。
开发人员确定如何最好地使用代码将该功能构建到应用程序中 - 包括处理数据的正确数据类型/对象。

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.

这篇关于在java中将String转换为Integer的最有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆