java.lang.String.copyValueOf(char[] data, int offset, int count)方法實例
java.lang.String.copyValueOf(char[] data, int offset, int count) 方法返回表示指定的數組中字符序列的字符串。
聲明
以下是**java.lang.String.copyValueOf()**方法的聲明
public static String copyValueOf(char[] data, int offset, int count)
參數
data -- 這是字符數組。
offset -- 這是最初的子數組的偏移量。
count -- 這是子數組的長度。
返回值
此方法返回表示指定的數組中字符序列的字符串。
異常
- NA
例子
下面的例子顯示java.lang.String.copyValueOf()方法的使用。
package com.yiibai; import java.lang.*; public class StringDemo { public static void main(String[] args) { // character array char[] charArr = { 'C', 'O', 'M', 'P', 'I', 'L', 'E', ' ', 'O', 'N', 'L', 'I', 'N', 'E' }; /* returns a String that contains the characters of the character
array with offset as 8 and length as 6 */ String str = String.copyValueOf(charArr, 8, 6 ); // prints the substring with length as 6 System.out.println(str); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
ONLINE