Answers for "TreeSet sprt"

0

TreeSet

// par défaut
TreeSet ensemble = new TreeSet();
// comparateur
Comparator comparateur = new Comparateur();
TreeSet ensemble = new TreeSet(comparateur);

// classe Comparateur implémentant l'interface Comparator
public class Comparateur implements Comparator {
  public int compare(Object obj1, Object obj2){
    return ((Comparable)obj2).compareTo(obj1);
  }
  public boolean equals(Object obj){
    return this.equals(obj);
  }
}
Posted by: Guest on October-31-2020
1

treeset

TreeSet: Can contain only unique values and it is sorted in ascending order
TreeMap: Can contain only unique keys and keys are sorted in ascending order.
Posted by: Guest on December-05-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language