Java Arrays Quiz - Multiple Choice Questions And Answers
Q. How do you declare an array in Java?
A. int[] arrayName;B. arrayName[] int;
C. int arrayName[];
D. int arrayName();
Q. How do you access an element from an array in Java?
A. arrayName(elementIndex);B. arrayName[index];
C. arrayName.index()
D. index.arrayName();
Q. What is the length of an array in Java?
A. size()B. length()
C. size
D. length
Q. How do you initialize an array in Java?
A. int[] arrayName = new int[5];B. arrayName = new int[5];
C. int arrayName() = new int[5];
D. int[] arrayName = {1, 2, 3, 4, 5};
Q. Can the size of an array be changed after it is created?
A. YesB. No
Q. How do you iterate through elements in an array in Java?
A. Using a for loopB. Using a while loop
C. Using a do-while loop
D. All of the above
Q. How do you find the maximum element in an array in Java?
A. Using a loop and comparisonB. Using the Math.max() method
C. Using the Collections.max() method
D. All of the above
Q. How do you sort an array in ascending order in Java?
A. Using a loop and swappingB. Using the Arrays.sort() method
C. Using the Collections.sort() method
D. All of the above
Q. What is the purpose of the Predicate functional interface in Java 8?
A. To produce resultsB. To consume values
C. To filter elements based on a condition
D. To transform values
Q. How do you copy an array in Java?
A. Using a loop and assignmentB. Using the Arrays.copy() method
C. Using the System.arraycopy() method
D. All of the above