问题 单项选择题

下面程序执行后,屏幕上显示的应是______。
public class Testl0

public static void main(String[] args)

char char1[] = ’t’, ’e’, ’s’, ’t’;
char char2[] = (’t’, ’e’, ’s’, ’t’, ’1 ;
String s1 = new String(char1);
String s2 = new String(char2, 0, 4);
System. out.println (si.equal (s2));

A.true

B.false

C.test

D.编译错误

答案

参考答案:A

解析: 首先可以通过字符数组来生成一个字符串对象:
String(char[]value);
String(char[]value,int startlndex,int numChars);
其中,startlndex指定字符串在数组中的起始下标,numChars表示字符个数。然后再测试字符串是否相等,可调用equal()方法,两串相等则返回true,否则返回false。

单项选择题
单项选择题