Java copyValueOf() 方法

返回到:Java 介绍String类

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 — 子数组的长度。

返回值

如字符串与指定 StringBuffer 表示相同的字符序列,则返回 true;否则返回 false。

实例

public class Test {
	public static void main(String args[]) {
		char[] Str1 = {'h', 'e', 'l', 'l', 'o', ' ', 'w', 'e', 'b', '1', '7', '6' };
		String Str2 = "";

		Str2 = Str2.copyValueOf( Str1 );
		System.out.println("返回结果:" + Str2);

		Str2 = Str2.copyValueOf( Str1, 2, 6 );
		System.out.println("返回结果:" + Str2);
	}
}

以上程序执行结果为:

返回结果:hello web176
返回结果:llo we

返回到:Java 介绍String类

作者:terry,如若转载,请注明出处:https://www.web176.com/java_api/19522.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2023年5月4日
下一篇 2023年5月4日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注