|
@@ -78,12 +78,9 @@ public class Arraz<T> {
|
78
|
78
|
|
79
|
79
|
public T[] createEmptyGenericArray(T[] array, int length) {
|
80
|
80
|
Class cl = array.getClass();
|
81
|
|
- if (!cl.isArray()) {
|
82
|
|
- return null;
|
83
|
|
- } else {
|
84
|
|
- T[] copy = (T[]) Array.newInstance(cl.getComponentType(), length);
|
85
|
|
- return copy;
|
86
|
|
- }
|
|
81
|
+ T[] copy = (T[]) Array.newInstance(cl.getComponentType(), length);
|
|
82
|
+
|
|
83
|
+ return copy;
|
87
|
84
|
}
|
88
|
85
|
|
89
|
86
|
public T[] copyArrayByIterator(T[] array) {
|
|
@@ -249,14 +246,14 @@ public class Arraz<T> {
|
249
|
246
|
return newArray;
|
250
|
247
|
}
|
251
|
248
|
|
252
|
|
- public boolean check2ArraysForEquals(T[] array1, T[] array2){
|
|
249
|
+ public boolean check2ArraysForEquals(T[] array1, T[] array2) {
|
253
|
250
|
if (Arrays.equals(array1, array2)) {
|
254
|
251
|
return true;
|
255
|
252
|
}
|
256
|
253
|
return false;
|
257
|
254
|
}
|
258
|
255
|
|
259
|
|
- public double averageArrayWithoutMaxMin(int[] array){
|
|
256
|
+ public double averageArrayWithoutMaxMin(int[] array) {
|
260
|
257
|
double sum = 0;
|
261
|
258
|
int dupes = 0;
|
262
|
259
|
|
|
@@ -271,7 +268,7 @@ public class Arraz<T> {
|
271
|
268
|
return sum / (array.length - dupes);
|
272
|
269
|
}
|
273
|
270
|
|
274
|
|
- public boolean arrayHas65And77(int[] array){
|
|
271
|
+ public boolean arrayHas65And77(int[] array) {
|
275
|
272
|
if (containsValue(array, 65) && containsValue(array, 77)) {
|
276
|
273
|
return true;
|
277
|
274
|
}
|
|
@@ -279,7 +276,7 @@ public class Arraz<T> {
|
279
|
276
|
return false;
|
280
|
277
|
}
|
281
|
278
|
|
282
|
|
- public boolean theTotalofTensIs30(int[] array){
|
|
279
|
+ public boolean theTotalofTensIs30(int[] array) {
|
283
|
280
|
int sum = 0;
|
284
|
281
|
|
285
|
282
|
for (int integer : array) {
|
|
@@ -296,19 +293,19 @@ public class Arraz<T> {
|
296
|
293
|
}
|
297
|
294
|
|
298
|
295
|
|
299
|
|
- public int findSmallestOfArray(int[] array){
|
|
296
|
+ public int findSmallestOfArray(int[] array) {
|
300
|
297
|
return findMin(array);
|
301
|
298
|
}
|
302
|
299
|
|
303
|
|
- public int findSecondSmallestOfArray(int[] array){
|
|
300
|
+ public int findSecondSmallestOfArray(int[] array) {
|
304
|
301
|
int indexOfSmallest = findIndexOf(array, findSmallestOfArray(array));
|
305
|
302
|
array[indexOfSmallest] = findMax(array);
|
306
|
303
|
|
307
|
304
|
return findMin(array);
|
308
|
305
|
}
|
309
|
306
|
|
310
|
|
- public int[] makeMeACopyPlease(int[] array){
|
311
|
|
- return reverseArray(array);
|
|
307
|
+ public int[] makeMeACopyPlease(int[] array) {
|
|
308
|
+ return reverseArray(array);
|
312
|
309
|
}
|
313
|
310
|
|
314
|
311
|
public T[] removeFromIndex(T[] array, int index) {
|
|
@@ -348,21 +345,20 @@ public class Arraz<T> {
|
348
|
345
|
return newArray;
|
349
|
346
|
}
|
350
|
347
|
|
351
|
|
- public List[] sortArrayIntoEvensThenOdds(int[] array){
|
352
|
|
- List[] evensThenOdds = new ArrayList[2];
|
353
|
|
- List<Integer> evens = new ArrayList<>();
|
354
|
|
- List<Integer> odds = new ArrayList<>();
|
|
348
|
+ public ArrayList<Integer> sortArrayIntoEvensThenOdds(int[] array) {
|
|
349
|
+ ArrayList<Integer> arrayList = new ArrayList<>();
|
|
350
|
+ int indexOfEvens = 0;
|
355
|
351
|
|
356
|
|
- for (int integer : array) {
|
357
|
|
- if (integer % 2 == 0) {
|
358
|
|
- evens.add(integer);
|
|
352
|
+ for (int integer: array) {
|
|
353
|
+ if (integer % 2 ==0) {
|
|
354
|
+ arrayList.add(indexOfEvens, integer);
|
|
355
|
+ indexOfEvens++;
|
359
|
356
|
} else {
|
360
|
|
- odds.add(integer);
|
|
357
|
+ arrayList.add(integer);
|
361
|
358
|
}
|
362
|
359
|
}
|
363
|
360
|
|
364
|
|
- evensThenOdds[0] = evens; evensThenOdds[1] = odds;
|
365
|
|
- return evensThenOdds;
|
|
361
|
+ return arrayList;
|
366
|
362
|
}
|
367
|
363
|
|
368
|
364
|
}
|