DEV Community

lou
lou

Posted on

L'interface Comparable en Java bDarija

L'interface Comparable kaykon f java.lang. Comparable lghaya mno howa moqaranat les objets dial chi classe bl'instance dial nefs dik lclasse, wadifa dialha katsehel tertib lma3loumat dial les objets li tabein la classe. lmefrod ela la classe li bagha dir comparaison les instances lowl dir l'implementation dial Comparable<T>. Had l'interface kay3tik methode smitha compareTo () li katakhod flparametre l'objet dial la classe

la methode compareTo() kadir lmoqarana mabin 2 strings mo3jamian bima3na ana :{"az", "ad"} katrjee {"ab", 'az"}.

lmoqarana katbasa ela Unicode dial kolla caractere fstring.

Btali kat-retourner 0 ila string lqah kaytsawa mea string l akher.

kat-retourner qel men 0 ila string endo 3adad a7rof qel men string l akher.

O kber men 0 ila string endo 3adad ahrof kber mn string l akher.

Example dial programme:

public class Etudiant implements Comparable<Etudiant> {

private String nom, cin;

 @Override
   public int compareTo(Etudiant e) {
      return this.cin.compareTo(e.cin);
   }

}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)