Java 中的copyValueOf()方法

目录
文章目录隐藏
  1. 语法
  2. 参数
  3. 返回值
  4. 实例

copyValueOf() 方法有两种形式:

  • public static String copyValueOf(char[] data): 返回指定数组中表示该字符序列的字符串。
  • public static String copyValueOf(char[] data, int offset, int count): 返回指定数组中表示该字符序列的 字符串。

语法

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

参数

  • data — 字符数组。
  • offset — 子数组的初始偏移量。。
  • count — 子数组的长度。

返回值

返回指定数组中表示该字符序列的字符串。

实例

public class Test {
    public static void main(String args[]) {
        char[] Str1 = {'h', 'e', 'l', 'l', 'o', ' ', 'm', 'y', 'b', 'j'};
        String Str2 = "";
 
        Str2 = Str2.copyValueOf( Str1 );
        System.out.println("返回结果:" + Str2);
 
        Str2 = Str2.copyValueOf( Str1, 2, 6 );
        System.out.println("返回结果:" + Str2);
    }
}

以上程序执行结果为:

返回结果:hello mybj
返回结果:llo my

「点点赞赏,手留余香」

0

给作者打赏,鼓励TA抓紧创作!

微信微信 支付宝支付宝

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
码云笔记 » Java 中的copyValueOf()方法

发表回复