Java, Interview Questions, Programming, Software Development.
names.add("Bob"); names.add("Charlie"); TreeSet: When to use: When you need to store elements in a natural order or a custom sorted order, or you need to perform range operations. TreeSet<String> sortedNames = new TreeSet<>(); sortedNames.add("Alice"); sortedNames.add("Bob");