Integer.toString(int i)vs String.valueOf(int i) [英] Integer.toString(int i) vs String.valueOf(int i)

查看:124
本文介绍了Integer.toString(int i)vs String.valueOf(int i)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么方法 String.valueOf(int i)存在?我正在使用此方法将 int 转换为 String ,然后才发现 Integer.toString( int i)方法。

I am wondering why the method String.valueOf(int i) exists ? I am using this method to convert int into String and just discovered the Integer.toString(int i) method.

在查看这些方法的实现后,我看到第一个调用第二个方法。因此,我对 String.valueOf(int i)的所有调用都涉及一次调用,而不是直接调用 Integer.toString(int i)

After looking the implementation of these methods I saw that the first one is calling the second one. As a consequence all my calls to String.valueOf(int i) involve one more call than directly calling Integer.toString(int i)

推荐答案

只是两种不同的方式做同样的事情。这可能是一个历史原因(不记得是否有一个来到另一个之前)。

Just two different ways of doing the same thing. It may be a historical reason (can't remember if one came before the other).

这篇关于Integer.toString(int i)vs String.valueOf(int i)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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