You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Such empty arrays are typically useful as return values, so that the calling code only has to worry about dealing with an array, rather than a potential null value that may lead to a NullPointerException.
33
+
Such empty arrays are typically used as return values so that the calling code only has to worry about dealing with an array, rather than a potentially null value that may lead to a NullPointerException.
34
34
The length of an array must be a non-negative integer:
There are two orders that can exists in a multi dimensional array, i.e
68
+
There are two orders that can exist in a multidimensional array, i.e
69
69
_Row major_ and _Column major_
70
-
For ex, consider below matrix
70
+
ex, consider below matrix
71
71
72
72
<imgwidth="185"alt="screen shot 2016-08-31 at 9 50 23 pm"src="https://cloud.githubusercontent.com/assets/3439029/18155706/04e2045c-6fc5-11e6-847e-8d8f406de844.png">
73
73
@@ -106,14 +106,14 @@ Here the class of T has to be explicitly passed to the constructor. The return t
106
106
107
107
**Sorted Arrays**
108
108
109
-
Arrays are considered to be sorted in ascending order when each element on left of that element in a array is smaller then that element itself. Vice versa goes for descending order.
109
+
Arrays are considered to be sorted in ascending order when each element on the left of that element in an array is smaller than that element itself. Vice versa goes for descending order.
110
110
111
111
**Pros:**
112
112
- Accessing an element is fast using the index - access time is O(1).
113
113
- Much faster to process - see this question.
114
114
115
115
**Cons:**
116
-
- Insertion and deletion are slow, subsequent elements must be moved - complexity for insertion in that case is O(n).
116
+
- Insertion and deletion are slow, subsequent elements must be moved - complexity for insertion, in that case is O(n).
117
117
- A large enough block of memory is needed to hold the array.
118
118
- Easily corrupted (data could be inserted in the middle).
119
119
@@ -126,14 +126,14 @@ Arrays are considered to be sorted in ascending order when each element on left
126
126
|**Size**|_Fixed length. Cannot change the size after creation_|_Dynamic in size. Capacity grows as the elements are added_|
127
127
|**Content**|_Can contain primitive data types and objects_|_Objects only. No primitive data types_|
128
128
|**Dimension**|_Can be multi-dimensional_|_Normally single dimensional, but can be made multi dimensional_|
129
-
|**Type Safety**|_Typesafe, meaning that array will contain objects of specific class or primitives of specific data type_|_Not typesafe by default. Generics can be used to make a List type safe_|
129
+
|**Type Safety**|_Typesafe, meaning that array will contain objects of specific class or primitives of specific data type_|_Not type-safe by default. Generics can be used to make a List type safe_|
130
130
|**Insertion/Deletion**|_Shifting existing elements may be needed if action is performed not at the end of the array_|_Easy insertion/deletion methods provided_|
131
131
**************************************
132
132
133
133
**Disadvantages of Arrays**
134
-
-**Fixed Size**: The size of the array is static, i.e we define the size when we create the array, which can't change later on.
135
-
-**One block allocation**: To allocate the array in the beginning, we may not have enough memory to hold entire array because of continous block of allocation.
136
-
-**Complex position based insertion**: This is applicable only in case of dynamic array or list, where size can change. If we want to insert an element at position n, we have to shift all the elements in the right by one position to make space for this new element, which is a time consuming and costly operation.
134
+
-**Fixed Size**: The size of the array is static, i.e we define the size when we create the array, which can't change later on.
135
+
-**One block allocation**: To allocate the array, in the beginning, we may not have enough memory to hold entire array because of continuous block of allocation.
136
+
-**Complex position based insertion**: This is applicable only in case of dynamic array or list, where size can change. If we want to insert an element at position n, we have to shift all the elements to the right by one position to make space for this new element, which is a time consuming and costly operation.
137
137
138
138
**Operations on Arrays**
139
139
@@ -145,7 +145,7 @@ Below operations on Arrays are implemented [here](../Arrays/BasicOperations.java
0 commit comments