Allam, Rose Ann L.
BSIT-1
Prof. Joey Arellano
1. Array can be accessed using [], while the arraylist can access elements using a set of members and
modify them. In array, we cannot change the length of array once created, but in java ArrayList it can be
changed. In ArrayList, we cannot store primitives because it can only store objects. But array can contain
both primitives and objects in Java.
2. You cannot change the size of the array after it’s constructed. Because if you create an array by
initializing its values directly, the size will be the number of elements in it. However, you can change the
number of elements in an ArrayList whenever you want
3. To find the length of an array, use array data member ‘length’. The ‘length’ gives the number of
elements allocated, not the number inserted. (Length of Array = size of array/size od 1 datatype)
4. Array elements are initialized with their default value that is 0 for integers.
5. In Java, when accessing the element from a 2D array using arr[first][second], the first index can be
thought of as the desired row, and the second index is used for the desired column. Just like 1D arrays,
2D arrays are indexed starting at 0.
6. An array can be of any data type, but can only hold a single data type. Specifically, you can declare an
array that holds integers, but you cannot declare a single array that holds both strings and integers. An
array can only hold a single type.
7. To initialize an Array with default values in Java, the new keyword is used with the data type of the
Array the size of the Array is then placed in the rectangular brackets. Int [] myArr = new int[10]; The
code line above initializes an Array of size 10.
8. 2.247.483.647 elements
9. A simple way is to run a loop and compare elements one by one. The Arrays. Equals() method checks
the quality of the two arrays in terms of size, data, and order of elements.
10. This can be accomplished by looping through the first array and store the elements of the first array
into the second array at the corresponding position.
- Start
- Initialize arr [] ={1, 2, 3, 4, 5}
- create arr2[] of size arr1[]
- copy elements of arr1[] to arr[]2
- repeat step 6 until (I<arr1.length)
- arr2[I] =arr1[I]
- display elements of arr1[]
- repeat step 9 until (I<arr1.length)
- print arr1[I]
- display elements of arr2[]
- repeat step 12 until (I<arr2.length)
- print arr2[I]
- end