Given the following declaration: int[] intArr;
select the correct way to get the number of elements in the array:
1. intArr[ ].length( )
2. intArr.length( )
3. intArr.length
4. intArr[ ].size( )
5. intArr.size( )
3.
- Each array object has a member variable named public final length of type ‘int’ that contains the size of the array.
True/false:
All types of arrays are objects. i.e. intArr instanceof Object is true.
True.
Which of the following statements will correctly create and initialize an array of Strings to non null elements:
2, 3, 4, 5
Given the following code:
int i = 0 ;
int[] iA = {10, 20} ;
iA[i] = i = 30 ;
What is iA[0], iA[1] and i
iA[0] = 30 iA[1] = 20 i = 30
Which of the following are benefits of an array over an ArrayList:
1, 2
- An ArrayList resize dynamically at run time as per the situation. An array cannot be resized once created.
Consider the following, what will it print:
boolean[] b1 = new boolean[2];
boolean[] b2 = {true , false};
System.out.println
( “” + (b1[0] == b2[0]) + “, “+ (b1[1] == b2[1]));
false, true
Consider the following code, what will it print:
String[][][] arr=
{{ { “a”, “b” , “c”}, { “d”, “e”, null } },
{ {“x”}, null },{{“y”}},{ { “z”,”p”}, {} }};
System.out.println(arr[0][1][2]);
null
Consider the following code, what will it print:
List s1 = new ArrayList( );
s1.add("a");
s1.add("b");
s1.add(1, "c");
List s2 = new ArrayList( s1.subList(1, 1) );
s1.addAll(s2);
System.out.println(s1);a, c, b
Which of the following will compile successfully:
1, 2, 3
Which of the following declarations are valid:
1, 2, 3, 4
Identify the correct statements about ArrayList:
2, 3, 5
Which of the following correctly declare a variable which can hold an array of 10 integers:
1, 3
Identify the correct statements about ArrayList:
1, 2, 5