Kollekciók – LinkedHashSet
package kollekciok.linkedhashset;
import java.util.Iterator;
import java.util.LinkedHashSet;
public class KollekciokLinkedHashSet {
public static void main(String[] args) {
/* LinkedHashSet: NEM rendezett, NEM ismétlődhetnek benne az elemek,
NEM használ kulcsot. Viszont SORRENDTARTÓ!!! */
LinkedHashSet<String> ffiNevek = new LinkedHashSet();
LinkedHashSet<String> noiNevek = new LinkedHashSet();
ffiNevek.add("Balambér"); noiNevek.add("Pompónia");
ffiNevek.add("Ödön"); noiNevek.add("Pompónia");
ffiNevek.add("Jukundusz"); noiNevek.add("Immakuláta");
ffiNevek.add("Fernándó"); noiNevek.add("Szüntüké");
ffiNevek.add("Ödön"); noiNevek.add("Küllikki");
System.out.print("Férfi nevek: " + ffiNevek + "\n");
System.out.print("Női nevek: " + noiNevek + "\n");
System.out.println(noiNevek.size() + " női név van a noiNevek-ben.");
System.out.println("A ffiNevek tartalmazza a Balambér nevet? " + ffiNevek.contains("Balambér"));
noiNevek.remove("Pompónia");
System.out.println(noiNevek.size() + " női név van a noiNevek-ben.");
Iterator<String> it = ffiNevek.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
// for(String s : ffiNevek){
// System.out.println(s);
// }
/* LinkedHashSet átalakítása tömbbé */
String[] sztringTomb = new String[ffiNevek.size()];
ffiNevek.toArray(sztringTomb);
System.out.println(java.util.Arrays.toString(sztringTomb));
}
}