Java常用类习题 联系客服

发布时间 : 星期三 文章Java常用类习题更新完毕开始阅读8500df2c876fb84ae45c3b3567ec102de2bddfe0

Java常用类习题

一、选择题

1. 下列String类的( )方法返回指定字符串的一部分(选择一项)

A. extractstring() B. substring() C. Substring() D. Middlestring()

2.下列哪一个是正确的( )

A) HashTable的关键字和值都允许为null B) HashTable的关键字和值都不允许为null

C) HashTable的关键字允许为null,值不允许为null D) HashTable的关键字不允许为null,值允许为null 3.对于下列代码:

String str1=\String str2=\

String str3=new String(\

StringBuffer str4=new StringBuffer(\以下表达式的值为true的是( ) A) str1= =str2; C) str2= =str3; public class Test {

public static void main(String args[]){ String str=\ str.substring(3); str.concat(\ System.out.print(str); } }

A) DE B) DEXYZ C) ABCDE D) CDEXYZ 5.对于下列代码:

public class Example{

String str=new String(\char ch[]={'d','b','c'};

public static void main(String args[]){ }

public void change(String str,char ch[]){

str=\}

Example ex=new Example(); ex.change(ex.str,ex.ch);

System.out.println(ex.str+\

B) str1= =str4; D) str3= =str4;

4.以下程序段输出结果的是( )

}

B) hello and a

输出结果是: ( ) A) hello and d C) world and d

D) world and a

6.以下代码的运行结果是哪一项。( )

public class StringTest { } A)A.A C)A.B

B)B.A D)B.B

public static void mb_operate(String x,String y) { }

public static void main (String args[]) { }

String a=\String b=\mb_operate(a,b);

System.out.println(a+\x.concat(y); y=x;

7.以下代码的运行结果是哪一项。( )

public class StringArray Test { } A)20 C)22

B)21 D)23

public static void mb_swap(String [] s) { }

public static void main (String args[]) { }

String [] s={\mb_swap(s);

System.out.print(s[0]+s[1]); if(s.length<2) return; String t=s[0]; s[0]=s[1]; s[1]=t;

8.以下代码的运行结果是哪一项。( )

public class TestGetChars{

public static void main(String[] args){ }

A)Hello World!

B)Hello World!

Hello Hello! C)Hello World! World

D)World World

String myString = new String(\char [] yourString = new char[16];

myString.getChars(6,11,yourString,0);

System.out.println(myString); System.out.println(yourString);

}

9.以下代码的运行结果是哪一项。( )

public class TestStringContructor{

public static void main(String[] args){ } A)45555 C)90123

B)12345 D)4950515253

byte [] b = {49,50,51,52,53}; String myString = new String(b); System.out.println(myString);

}

10.以下代码的运行结果是哪一项。

public class J_Intern {

public static void main(String args[ ]) {

String s1 = \ String s2 = \ String s3 = \ String a0 = \ String s4 = a0 + \

String s5 = new String(\ String s6 = s5.intern( );

System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\ System.out.println(\

} }

A)s2==s1 s3==s1 s4!=s1 s5!=s1 s6==s1 C)s2==s1 s3==s1 s4!=s1 s5!=s1 s6!=s1

B)s2==s1

s3==s1 s4==s1 s5!=s1 s6==s1 s3==s1 s4!=s1 s5!=s1 s6==s1

D)s2!=s1

11.下面程序段的输出结果是( )

StringBuffer buf1=new StringBuffer(20);

System.out.println(buf1.length()+ ‘,’+buf1,capacity()); A) 0,20

B) 0,null

C) 20,20

D) 0,0

12.下面的语句序列的输出结果为( )

String s= “ABCD”; s.concat(“E”); s.replace(‘C’,‘F’); A)ABCDEF B)ABFDE

C)ABCDE

D)ABCD

13.下面的哪些程序片断可能导致错误? ( )

A) String s = \String t = \String k = s + t;

B) String s = \ String t;

D) String s = \ String t = s - \

t = s[3] + \

C) String s = \String standard = s.toUpperCase(); 14.给出下面的代码片断

1) public void create() { 2} Vector myVect;

3} myVect = new Vector(); 4} }

下面的哪些陈述为true(真)? ( )

A) 第二行的声明不会为变量myVect分配内存空间。 B) 第二行的声明分配一个到Vector对象的引用的内存空间。 C) 第二行语句创建一个Vector类对象。 D) 第三行语句创建一个Vector类对象。

E) 第三行语句为一个Vector类对象分配内存空间。

15.欲构造ArrayList类的一个实例,此类继承了List接口,下列哪个方法是正确的( )

A ) ArrayList myList=new Object(); B) List myList=new ArrayList(); C) ArrayList myList=new List(); A) s[10] 为 \

D) List myList=new List();

16.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; ( )

B) s[9] 为 null;