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

查看:26
本文介绍了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天全站免登陆