Java 8 onwards...
You can convert Collection to any collection (i.e, List, Set, and Queue) using Streams and Collectors.toCollection().
Consider the following example map
Map<Integer, Double> map = Map.of(
1, 1015.45,
2, 8956.31,
3, 1234.86,
4, 2348.26,
5, 7351.03
);
to ArrayList
List<Double> arrayList = map.values()
.stream()
.collect(
Collectors.toCollection(ArrayList::new)
);
Output: [7351.03, 2348.26, 1234.86, 8956.31, 1015.45]
to Sorted ArrayList (Ascending order)
List<Double> arrayListSortedAsc = map.values()
.stream()
.sorted()
.collect(
Collectors.toCollection(ArrayList::new)
);
Output: [1015.45, 1234.86, 2348.26, 7351.03, 8956.31]
to Sorted ArrayList (Descending order)
List<Double> arrayListSortedDesc = map.values()
.stream()
.sorted(
(a, b) -> b.compareTo(a)
)
.collect(
Collectors.toCollection(ArrayList::new)
);
Output: [8956.31, 7351.03, 2348.26, 1234.86, 1015.45]
to LinkedList
List<Double> linkedList = map.values()
.stream()
.collect(
Collectors.toCollection(LinkedList::new)
);
Output: [7351.03, 2348.26, 1234.86, 8956.31, 1015.45]
to HashSet
Set<Double> hashSet = map.values()
.stream()
.collect(
Collectors.toCollection(HashSet::new)
);
Output: [2348.26, 8956.31, 1015.45, 1234.86, 7351.03]
to PriorityQueue
PriorityQueue<Double> priorityQueue = map.values()
.stream()
.collect(
Collectors.toCollection(PriorityQueue::new)
);
Output: [1015.45, 1234.86, 2348.26, 8956.31, 7351.03]
Reference
Java - Package java.util.stream
Java - Package java.util