Phương thức valueOf() của chuỗi Java
Ví dụ
Trả về một chuỗi biểu diễn các kiểu dữ liệu khác nhau:
char[] myArray = {'a', 'b', 'c'}; System.out.println(String.valueOf(myArray)); System.out.println(String.valueOf('A')); System.out.println(String.valueOf(true)); System.out.println(String.valueOf(4.5f)); System.out.println(String.valueOf(5.2)); System.out.println(String.valueOf(12)); System.out.println(String.valueOf(1400L));
Định nghĩa và cách sử dụng
Phương thức valueOf()
trả về biểu diễn chuỗi của giá trị đã chỉ định.
Cú pháp
Một trong những điều sau đây:
public static String valueOf(boolean data )
public static String valueOf(char data )
public static String valueOf(char[] data )
public static String valueOf(char[] data , int start , int length )
public static String valueOf(double data )
public static String valueOf(float data )
public static String valueOf(int data )
public static String valueOf(long data )
public static String valueOf(Object data )
Giá trị tham số
Parameter | Description |
---|---|
data | Required. The data to be represented as a string. |
start | Optional. If a char array is provided, a subset of the array can be represented. This argument specifies where the subset starts. |
length | Optional. If a char array is provided, a subset of the array can be represented. This argument specifies the length of the subset. |
Chi tiết kỹ thuật
Trả về: | Một biểu diễn String của đối số. |
---|---|
Ném: | IndexOutOfBoundsException - Nếu phần bắt đầu hoặc độ dài là số âm hoặc phần bắt đầu + độ dài lớn hơn độ dài của mảng. |
Phiên bản Java: | Bất kì |
❮ Các phương thức chuỗi