30.11.2012 Views

Interfete • Ce este o interfat˘a ? • Definirea unei ... - Profs.info.uaic.ro

Interfete • Ce este o interfat˘a ? • Definirea unei ... - Profs.info.uaic.ro

Interfete • Ce este o interfat˘a ? • Definirea unei ... - Profs.info.uaic.ro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Interfat¸a Comparator<br />

Listing 8: Sortarea unui vector folosind un comparator<br />

import java . util .*;<br />

class Sortare {<br />

public static void main ( String args []) {<br />

Persoana p[] = new Persoana [4];<br />

p [0] = new Persoana (3 , " Ionescu ");<br />

p [1] = new Persoana (1 , " Vasilescu ");<br />

p [2] = new Persoana (2 , " Georgescu ");<br />

p [3] = new Persoana (4 , " Popescu ");<br />

}<br />

}<br />

Arrays . sort (p, new Comparator () {<br />

public int compare ( Object o1 , Object o2) {<br />

Persoana p1 = ( Persoana )o1;<br />

Persoana p2 = ( Persoana )o2;<br />

return (p1. nume . compareTo (p2. nume ));<br />

}<br />

});<br />

System . out . println (" Persoanele ordonate dupa nume :");<br />

for ( int i =0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!