-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathArrays.java
More file actions
29 lines (24 loc) · 992 Bytes
/
Arrays.java
File metadata and controls
29 lines (24 loc) · 992 Bytes
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
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 static <E extends Comparable> Pair<E> firstLast(ArrayList<E> a) {
return new Pair(a.get(0),a.get(a.size()-1));
}
public static <E extends Comparable> Comparable min(ArrayList<E> al) {
return Collections.min(al);
}
public static <E extends Comparable> Comparable max(ArrayList<E> al) {
return Collections.max(al);
}
public static <E extends Comparable> Pair minMax(ArrayList<E> al) {
return new Pair(min(al),max(al));
}
}