提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
字符串valueOf方法。
public class Main { public static void main(String[] args)/** 来自 时代Java - N o w J a v a . c o m**/ { char[] charArray = {'a', 'b', 'c', 'd', 'e', 'f'}; boolean booleanValue = true; char characterValue = 'Z'; int integerValue = 7; long longValue = 10000000001L; // L suffix indicates long float floatValue = 2.5f; // f indicates that 2.5 is a float double doubleValue = 133.333; // no suffix, double is default Object objectRef = "hello"; // assign string to an Object reference System.out.printf( "char array = %s\n", String.valueOf(charArray)); System.out.printf("part of char array = %s\n", String.valueOf(charArray, 3, 3)); /** 时 代 J a v a - nowjava.com **/ System.out.printf( "boolean = %s\n", String.valueOf(booleanValue)); System.out.printf( "char = %s\n", String.valueOf(characterValue)); System.out.printf("int = %s\n", String.valueOf(integerValue)); System.out.printf("long = %s\n", String.valueOf(longValue));