Collections.sort(testList);
Collections.reverse(testList);
ArrayList<ArrayList<String>> yourList = ...
Collections.sort(yourList, new Comparator<ArrayList<String>>() {
@Override
public int compare(ArrayList<String> one, ArrayList<String> two) {
return one.get(1).compareTo(two.get(1));
}
});
Collections.sort(coll); -> helps sort an arraylist.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class arraylistSorter {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int size;
do {
System.out.print("Enter array size (min: 5): ");
size = input.nextInt();
} while (!(size >= 5));
ArrayList<Integer> array = new ArrayList<>(size);
System.out.println("Enter the numbers: ");
for (int i = 0; i < size; i++) {
array.add(input.nextInt());
}
System.out.println("Unsorted array: "+ array);
Collections.sort(array);
System.out.println("Sorted array: " + array);
System.out.println("minimum value: ");
getMinimum(array);
System.out.println("maximum value: ");
getMaximum(array);
}
private static void getMinimum (ArrayList<Integer> arr) {
int min = arr.get(0);
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) < min) {
min = arr.get(i);
}
}
System.out.println(min);
}
private static void getMaximum (ArrayList<Integer> arr) {
int max = arr.get(0);
for (int i = 0; i < arr.size(); i++) {
if (arr.get(i) > max) {
max = arr.get(i);
}
}
System.out.println(max);
}
}
arrayListObject = (ArrayList<String>) arrayListObject
.stream()
.sorted()
.collect(Collectors.toList());
In
return Arrays.stream(words.split(" "))
.sorted(Comparator.comparing(s -> Integer.valueOf(s.replaceAll("D", ""))))
.reduce((a, b) -> a + " " + b).get();