TreeSet Details part 1 [Collection Framework]

  Рет қаралды 247,904

Durga Software Solutions

Durga Software Solutions

Күн бұрын

Пікірлер: 97
@amileyjones9082
@amileyjones9082 6 жыл бұрын
Well explained! Durga is a great teacher . As this video is 4 years old , i would like to mention here that till java 1.6 null was allowed in TreeSet but it was considered as bug and in java 7 null is not allowed now in TreeSet. From the documentation of TreeSet: NullPointerException - if the specified element is null and this set uses natural ordering, or its comparator does not permit null elements
@chandrasekharvalisetty1602
@chandrasekharvalisetty1602 3 жыл бұрын
Correct
@devendrasingraul8905
@devendrasingraul8905 3 жыл бұрын
Yes
@amitbm7497
@amitbm7497 2 жыл бұрын
Thank you for sharing this.
@ajinkyakottawar9502
@ajinkyakottawar9502 4 жыл бұрын
Don't have words to say thank you for Durga sir...😊 They teach us from very basic concepts and in very easy words with live examples, this way it help me to remember in easy way... Keep going sir...😊 Lot's of love to you and your family... ❤️ God bless you Sir... 🙏😇🙏
@RAHULKUMAR-ye7cj
@RAHULKUMAR-ye7cj 8 жыл бұрын
Durga sir is a very good teacher. In my whole life, i never meet with such type of sir who taught very well. Lots of confusion in java, but now my all dout is cleared. Thanku so much sir. Is there any video for android except sandeep sir. Please help me.
@jajatisahoo3831
@jajatisahoo3831 3 ай бұрын
For an empty tree-set, when trying to insert null as the first value, one will get NPE from JDK 7. From JDK 7 onwards, null is not at all accepted by TreeSet. However, up to JDK 6, null was accepted as the first value, but any insertion of more null values in the TreeSet resulted in NullPointerException. Hence, it was considered a bug and thus removed in JDK 7.
@ravikumarsunkhesvarapu9122
@ravikumarsunkhesvarapu9122 6 жыл бұрын
the way u teach is awesome
@atiqulny
@atiqulny 8 жыл бұрын
Very lively, engaging instructor, best in KZbin.
@jeetendrabarnwal
@jeetendrabarnwal 5 жыл бұрын
Thanks for these awesome videos... just wanted to add one point - null was allowed in Java 6 ..in Java 7 null is not allowed..
@saradasai7669
@saradasai7669 9 жыл бұрын
Thank you Sir. Your explanation is very good ,clear and easily understandable.
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 9 жыл бұрын
Sarada Sai View 42 videos on Collections in Java, kzbin.info/www/bejne/qHqWh55_qahjm6M View 5 videos on JSF, kzbin.info/www/bejne/qHLEYqqtjLGqZ7s View 50 videos on Oracle, kzbin.info/www/bejne/pomYiH2ZqdNmgdk View 35 videos on Hibernate, kzbin.info/www/bejne/iYubkpWHaNugmsU View 115 videos on Data Structures, kzbin.info/www/bejne/pXKkmnWHe7h4n80 View 58 videos on Struts, kzbin.info/www/bejne/pIrUpKGofaymh8k View 74 videos on Spring, kzbin.info/www/bejne/j6HWd4drZdKnntU View 41 videos on CRT, kzbin.info/www/bejne/nHW1n36GrtuFZ5Y View 12 videos on JAVA Reflections API & Annotations kzbin.info/www/bejne/eKmmqGOrid2NiNU View 39 videos on Java Real Time Project Implementation on Spring,Struts & Hibernate, kzbin.info/www/bejne/n3zRk2N3nLCNgJI View other videos on ADV JAVA kzbin.info/www/bejne/bmTNfaSKdsekh7c View 9 videos on ENUM, kzbin.info/www/bejne/imLJfoqtfp53Z6c View 16 videos on Serialization, kzbin.info/www/bejne/mHrdl6Wsmdlqp68
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 9 жыл бұрын
Durga Software Solutions Demo Sessions on youtube, Language Fundamentals(16 Videos)kzbin.info/www/bejne/m4W7lWtvqZ2hnas, Operators & Assignments(7 Videos)kzbin.info/www/bejne/Z3uqgIOeft6bd68, Flow Control(6 Videos)kzbin.info/www/bejne/jmfVhGyseZ5gp68.
@nisargmunjpara5431
@nisargmunjpara5431 9 жыл бұрын
Hello sir these are incredible stuff we are having. Thank you for it. I have question regarding constructors of "TreeSet(Collection c)." In treeset heterogenous objects are not allowed and what if we create/convert ArrayList collection "c"(or any collection object which consists heterogenous objects) into a TreeSet object with " new TreeSet(Collection c) " constructor???? Hows it possible? Thank you..!!!!
@jasonarora8911
@jasonarora8911 8 жыл бұрын
+Nisarg Munjpara There is no way if there are heterogenous elements.You will get exception.You have to remove heterogenous elements and then you can take advantage of TreeSet(Having duplicate removed + Sorting elements) but no order preserved
@Skripturz
@Skripturz 6 жыл бұрын
Thanks, I was wondering the same thing
@varunsen2802
@varunsen2802 5 ай бұрын
I think in Priority Queue also, heterogenous objects are not allowed, beacuse in PQ elements are inserted in a some sorted order.
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 5 ай бұрын
Hello Varun. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@rahulkad5392
@rahulkad5392 2 жыл бұрын
Good job sir 🥰
@techgyan6233
@techgyan6233 4 ай бұрын
Might be some changes in new java version that's why Null not support import java.util.TreeSet; public class InterfacePractice { public static void main(String[] args) { TreeSet treeSet = new TreeSet(); treeSet.add(null); System.out.println(treeSet); } } Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "k1" is null
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 4 ай бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@santoshaakubathini5937
@santoshaakubathini5937 6 жыл бұрын
Nicely explained.. Awesome..
@dhrub6
@dhrub6 8 жыл бұрын
Hi Sir, I am your student. I got a job after clearing my doubts in Collections and Threads. Thanks a lot. I have a Question. How will we break TreeSet property (it should store Objects in non sorted order)?
@rexsam3134
@rexsam3134 4 жыл бұрын
Nice one. You missed mentioning which Java version was used to run the code
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 4 жыл бұрын
Hello Seetesh. Thanks for your valuable feedback. It will boost us to do new things. Please subscribe to get updates about new videos. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@surendramishra4813
@surendramishra4813 6 жыл бұрын
One thing I am not able to understand please correct me if I am wrong, when 4. TreeSet t = new TreeSet(Collection c); is there then why we need 3. TreeSet t = new TreeSet(SortedSet s); even though SortedSet also a Collection
@sangeethagopi4362
@sangeethagopi4362 2 жыл бұрын
I too have the same doubt... someone please clear our doubt
@senthil7818
@senthil7818 10 жыл бұрын
Durga sir plz upload videos on map collections
@javadsa367
@javadsa367 8 ай бұрын
Before Java 7, it was possible to add null elements to an empty TreeSet.
@Rohith-ov7vr
@Rohith-ov7vr Жыл бұрын
in priorityque also the hetogeneous data not allowed
@horriblecoder7280
@horriblecoder7280 6 жыл бұрын
If you look at the internal implementation of the TreeSet, it uses natural ordering, that means TreeSet uses Comparable interface by default to sort its value by comparing other value. Just think programmatically, how will you compare the null value to other. Is it make sense to compare the value with other(NULL) which doesn't have any value in it. That's why java developer made it TreeSet such a way that, it will throw NullPointerExeption when you try to store null value.
@horriblecoder7280
@horriblecoder7280 6 жыл бұрын
null as first element was considered as bug in java 1.6
@jvsnyc
@jvsnyc 4 жыл бұрын
I believe that nulls are the second worst problem in all of computer science and programming. Inconsistent handling of them, i.e. are two nulls equal or not, etc. is the first.
@rohitlovesnature
@rohitlovesnature 7 жыл бұрын
sir, can you please provide videos on hashmap and map interface
@Modern_revolution
@Modern_revolution 5 жыл бұрын
Thank you so much for your help!
@manassahoo2750
@manassahoo2750 Жыл бұрын
Sit please imporve your graphics and light .
@algorithmsguide5076
@algorithmsguide5076 5 жыл бұрын
Thankyou sir ji !!
@devendrasingraul8905
@devendrasingraul8905 3 жыл бұрын
TreeSet t = new TreeSet(); // null is not allow for empty TreeSet t.add(null); for Empty TreeSet null is not allow . I am using java 1.8
@kamalapuramsivasankar7
@kamalapuramsivasankar7 10 ай бұрын
Thanks sir...
@I_am_J300
@I_am_J300 Жыл бұрын
sir i tried to add thiss......t.add(null) for empty set obj still getting exception.. Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.lang.Comparable.compareTo(Object)" because "k1" is null
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions Жыл бұрын
Hello Jishan. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@ashishshrivastava4532
@ashishshrivastava4532 6 жыл бұрын
Null is not allowed in TreeSet But allowed in Hash Set So I request you to correct this one.
@MayurKalambkar
@MayurKalambkar Жыл бұрын
in java 1.8 null value is not allowed in TreeSet. So you are showing program of which version.
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@sohrabalam9650
@sohrabalam9650 2 жыл бұрын
But in my JDK-8, I am adding null in empty TreeSet and getting NullPointerException. E.g. import java.util.TreeSet; public class TreeSetDemo { public static void main(String[] args) { TreeSet treeSet = new TreeSet(); treeSet.add(null); } } Result : Exception in thread "main" java.lang.NullPointerException
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 2 жыл бұрын
Hello Sohrab. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@addicted2headway
@addicted2headway Жыл бұрын
sir, i am trying to insert null value in empty treeset then also i am getting nullpointer exception
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@VarunKumar-yy5sr
@VarunKumar-yy5sr 6 жыл бұрын
As per explaination, heterogeneous objects are not allowed but also u said default sorting order for numbers is assessing and characters is alphabetical order. If it is the case y can't we insert heterogeneous elements like alphabets as some elements and numbers as some other elements. Because as per explaination numbers should sort in assending order and characters in alphabetical order. Please clarify.
@ajinzrathod
@ajinzrathod 3 жыл бұрын
If null value is not working even for first time. It was allowed till 1.6. Since 1.7, null value is not allowed even for first time.
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 3 жыл бұрын
Hello Ajinkya. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@pranavdeshpande9675
@pranavdeshpande9675 8 жыл бұрын
sir pls upload videos for Queue nad Map too...
@pal0106
@pal0106 10 жыл бұрын
what happens if we try to create a tree set with the third constructor using a collection of heterogeneous elements?
@surajmahtosbg
@surajmahtosbg 5 жыл бұрын
watch full video
@WonderfulSound8
@WonderfulSound8 5 жыл бұрын
I'm adding null as my first element, but I'm getting NPE))) Here's my code)) TreeSet treeSet = new TreeSet(); treeSet.add(null); System.out.println(treeSet);
@jvsnyc
@jvsnyc 4 жыл бұрын
Read Amiley Jones comment!
@senthil7818
@senthil7818 10 жыл бұрын
This collections videos is enough for collection interview question.?Expecting a reply.Thanks in advance
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 9 жыл бұрын
SENTHIL KUMAR View 9 videos on ENUM, kzbin.info/www/bejne/imLJfoqtfp53Z6c View 16 videos on Serialization, kzbin.info/www/bejne/mHrdl6Wsmdlqp68
@lipikabarman1012
@lipikabarman1012 Жыл бұрын
after 1.6 version it not working sir. We are not able to insert null value in TreeSet
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@Tarun1kumar1989
@Tarun1kumar1989 9 жыл бұрын
Hi Sir, I have added only null value then also i am getting null pointer exception. import java.util.*; class TreeSetDemo1 { public static void main(String[] args) { TreeSet t=new TreeSet(); t.add(null); System.out.println(t); } }
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 9 жыл бұрын
+Tarun Kumar Hello, We are very Happy to say Now you can access All DURGA Sir's Core Java with OCJP/SCJP Video Sessions. To get Maximum Benefit from these video sessions, compulsory you have to write notes also. Sir will dictate each and every point clearly. Demo Sessions on KZbin: 1. Language Fundamentals(16 Videos) kzbin.info/www/bejne/m4W7lWtvqZ2hnas 2. Operators &Assignments(7 Videos) kzbin.info/www/bejne/Z3uqgIOeft6bd68 3. Flow Control(6 Videos) kzbin.info/www/bejne/jmfVhGyseZ5gp68 4. Exception Handling (10 Videos) kzbin.info/aero/PLd3UqWTnYXOnSkaum39zWYI6bPb3i7liz Please give your valuable feedback and it is very important and helpful for us. Note:-If you are interested for full version of videos please revert back for more information. Fee : 6000/- Duration: 6-months DURGASOFT Online Training Team, Mobile : +91-7207 21 24 28 +91-8885 25 26 27 Mail ID : durgasoftonline@gmail.com , durgasoftonlinetraining@gmail.com
@rickyb8989
@rickyb8989 9 жыл бұрын
Same with me...getting NullPointerException...guess either Durga is wrong or it was previously allow in earlier jdk version(I am using jdk 1.8)
@CorporateKahani
@CorporateKahani 8 жыл бұрын
+ricky b hi ricky, it was possible until 1.6 version only
@aditya12all
@aditya12all 7 жыл бұрын
It says in the compatibility notes from Java 6 to Java 7 that the possibility of adding null to a TreeMap was a bug: oracle.com/technetwork/java/javase/…. See also: bugs.sun.com/bugdatabase/view_bug.do?bug_id=5045147
@parameshyannam8542
@parameshyannam8542 7 жыл бұрын
Sir, why TreeSet and TreeMap Are not allowed Heterogenious Objects ??
@anirbanmajumdar781
@anirbanmajumdar781 7 жыл бұрын
Because the underline data structure is Balanced Tree and it implements Set, so you cannot actually have sorting done on Hetrogenous objects.
@RAHULKUMAR-ye7cj
@RAHULKUMAR-ye7cj 8 жыл бұрын
How I know about unicode of a is 97 and unicode value of A is 65. I am confused here.
@iam_hindhu
@iam_hindhu 10 жыл бұрын
sir , i trying this program ( am using java 1.7) i have an doubt on Null Acceptance .... TreeSet treeSet=new TreeSet(); treeSet.add(null); System.out.println(" tree Set is : "+treeSet); if i want execute this program i got an Runtime Exception like : Exception in thread "main" java.lang.NullPointerException at java.util.TreeMap.compare(Unknown Source) at java.util.TreeMap.put(Unknown Source) at java.util.TreeSet.add(Unknown Source) at com.practice.collections.TreeSetExample.main(TreeSetExample.java:10) but in your sample example you didn't get any exception ... i got confused which one is correct Sir, You said TreeSet accepted null (for only one time) but in program i got error like what am mention above .... please clarify my doubt ...
@joerokcz
@joerokcz 9 жыл бұрын
if i tried to put null after an null insertion,what will happen?
@vishwanathtontanal2365
@vishwanathtontanal2365 8 жыл бұрын
Null value is not allowed in TreeSet. Not even single time.
@ajinzrathod
@ajinzrathod 3 жыл бұрын
Allowed till 1.6. Since 1.7, null value is not allowed even for first time.
@nitishkadam9323
@nitishkadam9323 7 жыл бұрын
getting null pointer exception while adding null in empty treeset ?? please explain.. thnks
@NikhilMaguluri
@NikhilMaguluri 7 жыл бұрын
from java 7 null insertion is not allowed in a treeset. In java 6 it is a bug, that allows null insertion into a empty treeset.
@RoyaLockz
@RoyaLockz 7 жыл бұрын
Allowing Null within a collection of unique values is generally considered bad practice and disallowed in a lot of implementations with a similar mentality. Could you describe a situation where you'd need to insert Null into a Set that it'd be beneficial and improve the overall code quality?
@vineetchaurasia7460
@vineetchaurasia7460 6 жыл бұрын
Null is not allowed
@srikanthr5935
@srikanthr5935 10 жыл бұрын
Hello sir, i am trying to insert null in an empty treeset but still i am getting null pointer exception does treeset really allows null acceptance for once
@ishansoni9819
@ishansoni9819 9 жыл бұрын
post ur code?
@srikanthr5935
@srikanthr5935 9 жыл бұрын
Ishan Soni package name; import java.util.Comparator; import java.util.HashSet; import java.util.TreeSet; public class treeset { public static void main(String []args) { TreeSet t1=new TreeSet(); t1.add(null); System.out.println(t1); } }
@bluesteel1
@bluesteel1 Жыл бұрын
3:21 null insertions are not allowed this is incorrect
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions Жыл бұрын
Hello Friend. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@JorgeChavez8
@JorgeChavez8 8 жыл бұрын
Number 6 is wrong, TreeSet doesn't allow you to insert null objects.
@tx30289
@tx30289 9 жыл бұрын
nice English :)
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 9 жыл бұрын
***** Hi, We are very Happy to say Our Expert Faculty Durga Sir's One-to-One Video Sessions on "Core Java with SCJP/OCJP" are available. Shooted from direct Class Room. YOu can access these videos from anywhere anytime. Around 200+ hours training, 178 Videos with clear explanation on every concept. 100% Satisfaction and Perfection in Subject guaranteed. For Demo Sessions Please call or drop a mail to us... DURGASOFT Online Training ph: 91-8885252627 mail :durgasoftonline@gmail.com, durgasoftonlinetraining@gmail.com Demo Sessions on youtube: 1. Language Fundamentals(16 Videos)kzbin.info/www/bejne/m4W7lWtvqZ2hnas 2. Operators & Assignments(7 Videos)kzbin.info/www/bejne/Z3uqgIOeft6bd68 3. Flow Control(6 Videos)kzbin.info/www/bejne/jmfVhGyseZ5gp68 durgasoft.com durgasoftonlinetraining.com facebook.com/durgasoftware durgajobs.com facebook.com/durgajobsinfo
@horriblecoder7280
@horriblecoder7280 6 жыл бұрын
his comment was sarcastic.
@vipulgujarathi_7379
@vipulgujarathi_7379 2 жыл бұрын
what is the default size of TreeSet Constructor?
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 2 жыл бұрын
Hello Vipul. Plz contact our online team durgasoftonlinetraining@gmail.com or call us on this number +918885252627, 7207212427/28
@Mbc43m276
@Mbc43m276 7 жыл бұрын
Why are there two separate constructors for creating an equivalent collection c and a sortedSet s? I.e TreeSet t =new TreeSet(Collection c) and TreeSet t =new TreeSet(SortedSet s). ? sorted set comes under the collection interface right? Someone please help
@horriblecoder7280
@horriblecoder7280 6 жыл бұрын
In first type of constructor the element order will be naturally sorted. In second type the element order will depend on the customized sorting order that already may have been used. suppose: contents of List x: 5,3,9,7 TreeSet t=new TreeSet(x); contents of TreeSet t:3,5,7,9 suppose: contents of TreeSet x:5,3,9,7 (custmizing in order is done under compare method) TreeSet t=new TreeSet(x); contents of TreeSet t:5,3,9,7 Hence order also moves. For more info read documentation docs.oracle.com/javase/8/docs/api/java/util/TreeSet.html
@HemantShori
@HemantShori 6 жыл бұрын
you had me at medile
@shilpa3645
@shilpa3645 10 жыл бұрын
treeset not allowed null
@DurgaSoftwareSolutions
@DurgaSoftwareSolutions 10 жыл бұрын
Yah Shilpa until 1.6 version we can add null to the TreeSet. But from 1.7 version onwards we cannot add null to the TreeSet.This is a small difference wrt versions.
@Nitinkandwal
@Nitinkandwal 8 жыл бұрын
null is not allowed in TreeSet.
@pratikbhardwaj3804
@pratikbhardwaj3804 6 жыл бұрын
from 1.7 version
@surendramishra4813
@surendramishra4813 6 жыл бұрын
Nitin Kandwal first see full video
@farhadbaghirov9075
@farhadbaghirov9075 5 жыл бұрын
+ Kabir Kandwal null is allowed Let's look at the example shown below: class data1 { Integer number; public data1(Integer number) { this.number = number; } @Override public String toString() { return ""+number; } } TreeSet data2set = new TreeSet(new Comparator() { @Override public int compare(data1 d1,data1 d2) { int d1n=d1==null ? 0 : d1.number; int d2n=d2==null ? 0 : d2.number; return d1n-d2n; } }); data2set.add(null); data2set.addAll(Arrays.asList(null,null)); System.out.println(data2set);//[null]
@Vishwasp13
@Vishwasp13 5 жыл бұрын
@@farhadbaghirov9075 Customising the comparator and removing null doesn't imply null is allowed. The trick is good but might confuse others.
TreeSet Details part 2
8:45
Durga Software Solutions
Рет қаралды 173 М.
SortedSet Details [Collection Framework]
11:24
Durga Software Solutions
Рет қаралды 187 М.
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 4,4 МЛН
Random Emoji Beatbox Challenge #beatbox #tiktok
00:47
BeatboxJCOP
Рет қаралды 65 МЛН
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 2,3 МЛН
ArrayList details (Collection Framework)
32:52
Durga Software Solutions
Рет қаралды 575 М.
Set and HashSet in Java - Full Tutorial
20:43
Coding with John
Рет қаралды 230 М.
TreeSetDetails part 3
15:38
Durga Software Solutions
Рет қаралды 157 М.
TreeSet Details part 5
29:27
Durga Software Solutions
Рет қаралды 157 М.
LinkedList details ( Collection Framework)
20:44
Durga Software Solutions
Рет қаралды 375 М.
HashSet (Collection Framework)
17:57
Durga Software Solutions
Рет қаралды 355 М.
Java Collections Explained (with examples)
10:39
Visual Computer Science
Рет қаралды 93 М.
Three Cursors of Java - Iterator  (Collection Framework)
17:51
Durga Software Solutions
Рет қаралды 257 М.
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 4,4 МЛН