ArrayList interview

2.

The following Java code, the output running result is ( A   ). (select one) 

 

public class Test {

public static void main(String[ ] args) {

List<String> list=new ArrayList<String>();

list.add("str1");

list.add(2, "str2");

String s=list.get(1);

System.out.println(s);

}

}

 

 

 

 

A

An exception occurred while running

 

B.

run correctly, output str1

 

C.

run correctly, output str2

 

D.

An exception occurred when compiling

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324780404&siteId=291194637