Java Set

preview_player
Показать описание
The Java Set interface represents a set (collection) of objects in Java which is unordered, and where each element is unique, meaning each element is only present once in a Java Set. A Java Set is a handy way to sort out duplicats from an array or List. Add all the elements to a Java Set, and each element will only exist once in the Set when you are done. This is different from a Java List or arrays where the elements can be present multiple times.

Chapters
0:00 Java Set introduction
0:45 Java Set vs. Java List
1:36 Java Set implementations
2:43 Java Set generic types
3:26 Add elements to a Java Set
5:07 Iterate elements of a Java Set using Iterator
6:14 Java HashSet vs. Java TreeSet
7:22 Iterate elements of a Java Set using for-each loop
8:05 Iterate elements of a Java Set using the Java Streams API
9:07 Remove element from a Java Set
10:06 Remove all elements from a Java Set
10:18 Add all elements from a Java Collection to a Java Set
11:22 Remove all elements in a Java Collection from a Java Set
12:10 Retain all elements from a Java Collection in a Java Set
12:54 Java Set size - obtain number of elements in a Java Set
13:24 Check if Java Set is empty
13:50 Check if Java Set contains specific element
14:34 Convert Java Set to a Java List

Here is a textual version of this Java Set tutorial:

Here are links to my Java List tutorials:

Java Streams Tutorial - text / video:
Рекомендации по теме
Комментарии
Автор

Mr Jenkov, I want to take this opportunity to thank you for your videos. They helped me tremendously while I was doing my CS degree (quite few years back now) . You teach very clearly at a nice pace, which definitely contributed to my Java learning.

snewnham
Автор

Mr. Jakob, thank you! Your videos are wonderful! They are among the most comprehensive and comprehending materials out there! I hope you get enough rewards for what you're doing!

a_suslov
Автор

One point i noted in practice: Set<String> s = Set.of("1", "str", "7", "str2"); This Set.of() initialization makes set immutable. no add, remove, removeAll() functions works on set s.. me if i am wrong.

shivamtyagi
Автор

Another great video from jenkov! Please also include the runtime of Java collections :)

Hashset set of unique elements unordered, if you want ordered hash can use Treeset instead of Hashset or hash map implementation linked hash map.
Treeset ordered using comparator not the order of insertion, but a linked hash map will order according to insertion

mostinho
Автор

you got one of these audiobook voices, super nice to listen to

Syneptic
Автор

This channel is underrated, nice crisp video, subbed !!!, It would be great if you could also explain what happens when we do Set<List<Integer>>, how does contains work in such case

salmanasifs
Автор

Short and clear. Thanks for the video.

studyjava
Автор

Please make a full playlist on JavaFX. I have seen your website. Came here from there. Very impressive work.
Please make a full tutorial on JavaFX.

tanzeelahmed
Автор

Omg new video!! very waiting generic video tutorial

minepolz
Автор

THANK YOU!! This was SUPER helpful!! 😊😊😊💜💜

tabithae
Автор

Hello. Is it possible to use retainAll method in a set that is not like the one you use in your video. Example is set.add("1", "2", "3", "4", "5", "6", "7"); i want to print for example is number 7 how do i do that?

clausekinncaparida
Автор

Please activate the English subtitles to the whole series. Sometimes I need to read the subtitles to understand English. Thanks from Brazil.

JtubeMega
Автор

Great videos and had spent lot of time reading your blogs.. Somehow this video is not getting ranked/popped-up in youtube highly.. May be you have to improve on this to get more views.. :-)

basavaraj
Автор

Where is that link for streams, as promised in the video?

kamaudennis
Автор

I tried Set.of and it told me "The method of(String, String, String) is undefined for the type Set"

joneswafula