<span class="greencolor2">Enrol for Java Certification</span>
Certifications Boost Confidence. Go through Certifications CENTER
Study and learn Interview MCQ Questions and Answers on Java Arrays and Multidimensional Arrays. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.
Go through Java Theory Notes Arrays and Multidimensional Arrays before reading these objective questions.
That is the reason why Java Array has predefined methods.
Only initialization causes memory to be allocated.
int[] nums = {1,3,6};
No, you can not skip any elements. All elements need to be initialized in one go or at the same time.
It is a Lazy initialization of an array.
static int[] nums; public static void main(String args[]) { System.out.println(nums.length); }
int[] marks = {35,65,95}; System.out.print(marks.length + "," + marks[1]);
Array index starts with Zero (0). So marks[1] represents the second element.
int[] balls = {}; System.out.print(balls.length);
//int[] ary; ary.length()
//int[] ary; ary.length
//int[] ary; ary->length()
//int[] ary; ary->length
"length" is a field, not a method. So, parentheses are not required.
String[] colors = {"RED";"YELLOW";"WHITE"}; System.out.print(colors[2]);
Array elements must be separated with Comma(,)s.
public class Polo { public static void main(String args[]) { String[] computer = {"RAM","HDD","MOUSE"}; String[] parts = {computer[0],computer[2]}; System.out.print(parts[1]); } }
int ages[3] = {25, 27, 30}; System.out.println(ages[1]);
We should not mention the array size at the time of Shorthand Initialization. Error: Unresolved compilation problem: Syntax error on token "3", delete this token So make it like int ages[] = {25, 27, 30};
WRONG: int ary[2]={34,45}; RIGHT: int ary[] ={34,45};
Array index starts with 0. So, an index of 6 means 7th position. An index of N means, N+1 position.
An array can be of any data type, primitive or Object type.
Only lazy initialization of array needs the keyword "new" to allocate memory.
int[] ary; ary = new int[5];
Objects can be String, ArrayList, HashMap, HashSet etc.
null is nothing but '\0'.
int balls[], rounds=3; balls = new int[rounds]; for(int i=0; i<balls.length; i++) balls[i] = (i+1)*2; for(int j=0; j<balls.length; j++) System.out.print(balls[j] + ",");
String[] ary = {"KITE", "AIR"}; String str = "PLANE"; ary[1] = str; str = "FLY"; System.out.println(ary[1]);
An N-dimensional array is an array of (N-1) dimensional arrays.
int[][] code = {{1,2},{3,4,5}};
int[2][] code = {{1,2},{3,4,5}};
int[][] code={1,2, 3,4,5};
We should not mention the size of any row or column.
int[][] goats; goats = new int[3][]; goats[0] = {1,2}; System.out.println(goats[0][1]);
It is lazy initialization. So, you can not use braces { } to initialize. Use the keyword new. goats[0] = new int[2]; goats[0][0] = 1; goats[0][1]=2; System.out.println(goats[0][1]); //Output: 2
1 2 3 4 5 6
int ary[][]; ary = new int[5][];//first dimension is compulsory.
Open Certification Helper Popup Reset Popup