-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeSetTest.java
More file actions
28 lines (25 loc) · 792 Bytes
/
TreeSetTest.java
File metadata and controls
28 lines (25 loc) · 792 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
package treeSet;
import java.util.Comparator;
import java.util.NavigableSet;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* This program sorts a set of item by comparing their descriptions.
*
* @author Cay Horstmann
* @version 1.12 2015-06-21
*/
public class TreeSetTest {
public static void main(String[] args) {
SortedSet<Item> parts = new TreeSet<>();
parts.add(new Item("Toaster", 1234));
parts.add(new Item("Widget", 4562));
parts.add(new Item("Modem", 9912));
System.out.println(parts);
NavigableSet<Item> sortedByDescription = new TreeSet<>(
Comparator.comparing(Item::getDescription)
);
sortedByDescription.addAll(parts);
System.out.println(sortedByDescription);
}
}