-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathArrays.java
More file actions
33 lines (28 loc) · 1.18 KB
/
Arrays.java
File metadata and controls
33 lines (28 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package Pair;
import java.util.ArrayList;
import java.util.Collections;
/**
* In here you must make firstLast, which will return a pair of the first element in the array list and the last
* element in the arraylist.
* You must also make a min method that returns the smallest item in the array list
* A max method that returns the largest item in the arraylist
* And a minmax method that returns a pair containing the largest and smallest items from the array list
*/
public class Arrays {
public Arrays myArray = new Arrays();
public static <E extends Comparable> Pair<E> firstLast(ArrayList<E> a) {
return new Pair<E>(a.get(0),a.get(a.size()-1));
}
public static <E extends Comparable>E min(ArrayList<E> inputArrayList){
Collections.sort(inputArrayList);
return inputArrayList.get(0);
}
public static <E extends Comparable> E max(ArrayList<E> inputArrayList){
Collections.sort(inputArrayList);
return inputArrayList.get(inputArrayList.size()-1);
}
public static <E extends Comparable> Pair<E> minMax(ArrayList<E>inputArrayList){
Collections.sort(inputArrayList);
return firstLast(inputArrayList);
}
}