Java String copyValueOf(data, offset, count)方法

Java String copyValueOf(data, offset, count)方法將返回一個String,表示指定數組中的字元序列。

語法
以下是此方法的語法 -

public static String copyValueOf(char[] data, int offset, int count)

參數

  • data - 字元數組。
  • offset - 子數組的初始偏移量。
  • count - 子數組的長度。

返回值

  • 此方法返回包含字元數組字元的String值。

示例


public class Test {

    public static void main(String args[]) {
        char[] Str1 = { 'y', 'i', 'i', 'b', 'a', 'i', '.', 'c', 'o', 'm', 'd' };

        String Str2 = "";
        Str2 = Str2.copyValueOf(Str1, 2, 6);
        System.out.println("Returned String: " + Str2);
    }
}

執行上面示例代碼,得到以下結果:

Returned String: ibai.c

上一篇: java中方法重載和方法重寫的區別 下一篇:無