Set
StandardMethod set() biasanya digunakan untuk menge-set atau memberikan atau mengganti nilai property (variabel) milik sebuah objek.
contoh:
import java.util.*;
publicclassSetDemo{
publicstaticvoid main(String args[]){
int count[]={34,22,10,60,30,22};
Set<Integer>set=newHashSet<Integer>();
try{
for(int i=0; i<5; i++){
set.add(count[i]);
}
System.out.println(set);
TreeSet sortedSet=newTreeSet<Integer>(set);
System.out.println(“The sorted list is:”);
System.out.println(sortedSet);
System.out.println(“The First element of the set is: “+
(Integer)sortedSet.first());
System.out.println(“The last element of the set is:”+(Integer)sortedSet.last());
}
catch(Exception e){}
Tidak ada komentar:
Posting Komentar