This is an old revision of the document!
Το Set είναι ένα Collection το οποίο δεν επιτρέπει διπλές εγγραφές. Δείτε το παρακάτω παράδειγμα κώδικα που εξηγεί την λειτουργία του Set.
public class FindDups2 { public static void main(String[] args) { Set<String> uniques = new HashSet<String>(); Set<String> dups = new HashSet<String>(); for (String a : args) if (!uniques.add(a)) dups.add(a); // Destructive set-difference uniques.removeAll(dups); System.out.println("Unique words: " + uniques); System.out.println("Duplicate words: " + dups); } }
Ένα ενδεικτικό τρέξιμο είναι το παρακάτω
$> java FindDups2 me you me he he her see me you Unique words: [see, her] Duplicate words: [you, me, he]
Βασικές υλοποιήσεις του Set interface είναι οι παρακάτω:
| Προηγούμενο: Interface java.util.Collections | Περιεχόμενα | Επόμενο: Interface java.util.List |