将任何原始数据类型转换为字符串的最佳方法是什么? [英] What is the best way to convert any primitive data type to string

查看:136
本文介绍了将任何原始数据类型转换为字符串的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下方法将任何原始数据类型转换为字符串

I am using the following approach to convert any primitive data type to string

示例

int i = 5;//
String convertToString = ""+i;// convert any primitive data type to string

要将int数据类型转换为字符串,我可以使用 Integer.toString()但是什么是将任何类型的原始数据(不仅是int)类型转换为字符串的更好方法

To convert int data type to string i can use Integer.toString() but what is the better way to convert any type of primitive data (not only int) types to string

推荐答案

使用 String.valueOf()方法。

int no = 2;

String strValue = String.valueOf( no );

这篇关于将任何原始数据类型转换为字符串的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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