Moksha - Core Java FAQS Part 1
Core Java FAQS Part 1 Arrays: Question : What is an array in Java, and how do you declare and initialize one? Answer : An array in Java is a data structure that holds a fixed number of values of the same data type. To declare and initialize an array, you can use the following syntax: DataType[] arrayName = new DataType[size]; Example : int[] numbers = new int[5]; Question : How do you access elements in an array in Java? Answer : You can access elements in an array using the index (0-based). For example: int thirdElement = numbers[2]; // Accesses the third element (index 2) of the 'numbers' array. Question : Explain the difference between an array and an ArrayList. Answer : An array has a fixed size, while an ArrayList can dynamically grow or shrink. ArrayList is part of the Java Collections Framework and provides more functionality, but arrays are more memory-efficient for fixed-size collections. Question : H...